Increasing a custom property 1 for each new created company

ASabakji
Teilnehmer/-in

Hi,

 

At the company level, we have a custom field called "Accounts Receivable Number".
In this field we give each company such an ID for internal use.

We are looking for a way to not do this manually every time we create a new company, because every time we have to search what the last assigned number was from the last company created to increment this number by 1.

For new created companies this number should always increase by 1 automatically, e.g. first company has the number "6000" so the next created company will automatically have the number "6001" and the next then "6002" and so on.

In the HubSpot community I found out that this is possible with Operations Hub and I found the following code, which I can use in a "Custom code" action in my workflow.

But this code was written with an API Key, and API Keys are not available anymore. How can I make this code work with private apps?

const hubspot = require('@hub
spot/api-client');

exports.main = (event, callback) => {
callback(processEvent(event));
}

function processEvent(event) {
const hubspotClient = new hubspot.Client({
accessToken: process.env.privateApp
});
let companyId = event.object.objectId;
hubspotClient.crm.companies.basicApi.getById("6727326198", ["account_receivable_number"])
.then(results => {
let last_order = results.body.properties.company_id;
let current_order = ++last_order;
hubspotClient.crm.companies.basicApi.update(
companyId,
{properties: {["account_receivable_number"]: current_order}}
)
hubspotClient.crm.companies.basicApi.update(
"6727326198",
{properties: {["account_receivable_number"]: current_order}}
)
})

Thanks for any suggestions.

0 Upvotes
2 Antworten 2
Jaycee_Lewis
Vordenker/-in

Hi, @ASabakji, thanks for reaching out. 

 

Suggestion — it is helpful for the community if you include a link to the post where you sourced this code block from. You can also try tagging the original poster or user. If the post isn't too old, they may be able to provide help with their solution. Either way, seeing the link will be useful. 

 

One question — when you run this code block in its current state, does it return a specific error?

 

Best,

Jaycee





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
ASabakji
Teilnehmer/-in

Hi @Jaycee_Lewis,

 

Thanks for your Hint. I tried to edit the post, but it deos not work.

Here is the link to the article , where I have found the code.

 

Best regards

Ahmad

0 Upvotes