This idea is a needed one for sure. In the meantime you can do it with a workflow using a custom code action. Here is an example getting all the line items in a deal and then performing a calculation on each one and finally storing the result back in the line item - hope this helps you:
const hubspot = require(‘@hubspot/api-client’);
exports.main = async (event, callback) => {
/*****
Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
*****/
let response = ‘’;
let errmsg = ‘’;
let associations = ‘’;
let lineitem = ‘’;
let my_calculated_field = 0;
let success = false;
const hubspotClient = new hubspot.Client({ accessToken: process.env.HS_TOKEN });
try {
response = await hubspotClient.crm.deals.associationsApi.getAll(event.object.objectId, ‘line_item’);
if (response) {
associations = response.results;
for (let i=0; i<associations.length; i++) {
let properties = [“hs_cost_of_goods_sold, quantity”];
lineitem = await hubspotClient.crm.lineItems.basicApi.getById(associations[i].toObjectId, properties);
// do your calculation here
my_calculated_field = lineitem.properties.hs_cost_of_goods_sold * lineitem.properties.quantity;
properties = {
“my_calculated_field” : my_calculated_field ,
};
const prop_bag = { properties };
const lineItemId = lineitem.id;
const idProperty = undefined;
await hubspotClient.crm.lineItems.basicApi.update(lineItemId, prop_bag, idProperty);
success = true;
}
} catch (e) {
errmsg += "AN ERROR OCCURRED! " + e.message;
}
/*****
Use the callback function to output data that can be used in later actions in your workflow.
*****/
callback({
outputFields: {
associations: JSON.stringify(associations, null, 2),
errmsg: errmsg,
lineitem: JSON.stringify(lineitem, null, 2),
my_calculated_field : my_calculated_field ,
success: success
}
});
}