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.