So I just tried it, and it worked. Here’s what I did:
- Create a custom deal property called “Ordre Numérique” and make it a number property. (Seems like you already have that step done.)
- Create your test deal and set it’s “Ordre Numérique” to wherever you want the counting to start, minus one. (So if you want to start at 1, make it 0. If you already have a list of IDs that you want to add to, make it whatever the last one of those is.) For my example, I set the value to 607 (I chose this number at random), so we should expect the first deal to go through the workflow to get a value of 608 (and it did!)
- Copy the ID of the test deal (you can get that from the URL when you’re on the deal record).
- Create a deal-based workflow (you can use the one you already have) and set up your enrollment triggers (you’ve already done this). Then add a custom code action and write your code. Here’s the code I came up with:
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
callback(processEvent(event));
}
function processEvent(event) {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
let dealId = event.object.objectId;
hubspotClient.crm.deals.basicApi.getById("5257315659", ["ordre_numerique"])
.then(results => {
let last_order = results.body.properties.ordre_numerique;
let current_order = ++last_order;
hubspotClient.crm.deals.basicApi.update(
dealId,
{properties: {["ordre_numerique"]: current_order}}
)
hubspotClient.crm.deals.basicApi.update(
"5257315659",
{properties: {["ordre_numerique"]: current_order}}
)
})
}
Now, don’t just copy-paste this code and expect it to work! Here are some notes:
-
process.env.HAPIKEY
refers to a secret I created called HAPIKEY that has my HubSpot API key stored in it. You’ll need to get your API key (video explainer) and store it in a secret and then replace
HAPIKEY
with whatever you call your secret (unless you call it HAPIKEY).
-
5257315659
is the ID for the test deal I created. Your test deal will have its own ID. Whatever that ID is, put it in both places you see
5257315659
in this code.
-
ordre_numerique
is the internal name for the custom property I created. I’m guessing that’ll be the same for you, but you should double check first, just in case.
And that’s it. I’ve run three deals through this workflow in my own account, and the first one was given number 608, then the next one was given 609, and the third one was giving 610, which I think is exactly what you were going for.
Let me know if you have any trouble with it!
Kyle