Assigning property to contacts

Hi guys,

I am trying to change a property price_per_month which is currency string to a number, which I managed. And then overwrite this property by another pricing_price and add to contact so every contact which get currency string is then changed to number and assigned as pricing price so I can have it in my benchmarking afterwards for analyze.

Can anyone help?

I have this, but apparently there are errors…

const hubspot = require(‘@hubspot/api-client’);

var price_per_month;
var pricing_price;
var cur_re = /\D*(\d+|\d.*?\d)(?:\D+(\d{2}))?\D*$/;
var parts = cur_re.exec(price_per_month);
var number = parseFloat(parts[1].replace(/\D/,‘’)+‘.’+(parts[2]?parts[2]:‘00’));

pricing_price = number.toFixed(2);

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

function processEvent(event) {
const hubspotClient = new hubspot.Client({ apiKey: process.env.HAPIKEY });

let engage_id = event[‘price_per_month’];
// console.log(engage_id);

hubspotClient.crm.objects.basicApi
.getById(event.object.objectType, event.object.objectId, [“pricing_price”])
.then(results => {
let engage_enroll = results.body;
console.log(engage_enroll)

hubspotClient.crm.objects.associationsApi
.getAll(
event.object.objectType,
event.object.objectId,
[“contacts”]
)
.then(results => {
let associations = results.body.results;
let contact_ids = associations.map(a => a.id);
console.log(associations, contact_ids);

contact_ids.forEach(function (entry) {
hubspotClient.apiRequest({
method: ‘POST’,
path: `/automation/v2/workflows/22041022/enrollments/contacts/${entry}?hapikey=${process.env.HAPIKEY}`
});
});
}
)
}
)
}

Hey @DNalepa,

I might need you to help me to understand what you’re trying to achieve. Sharing your error logs would also be helpful.
What are you trying to do with the pricing_price variable? How are you looking to utilize it for your benchmarking? You’ve declared it, but I don’t see it being assigned a value at any point in your code. You’re carrying out your operations on a datapoint that doesn’t exist with your current setup.

let engage_id = event[‘price_per_month’];

I’m not sure if you’re trying to assign a key in an event object, or if you’re expecting there to be a value of some sort at event[‘price_per_month’].

If it’s the latter, I’d recommend using the inputFields at the top of the coded action node to bring in specific property values of an enrolled record. For example, adding “phone_number” using the options at the top would allow you to access that value on the enrolled record, in the event it’s populated via event.inputFields[“phone_number”].

If you can share some logs and further details, I’d be happy to offer some more helpful assistance.