Workflow with Custom Code

I have a contact property called “contact engagement score” and another contact property called “lead status”. Whenever the lead status is anything other thank “JUnk”, I want an average of all the contact engagement scores, to be input into a custom property at the company record.
Example:

contact A - 10
contact B - 5, but junk status
contact C - 16

then the average would be 13, and this value would be appended to the company record in another custom property
need the line of code to solve this using a hubspot workflow with ops hub steps

Hi @Manasa_V,

I wouldn’t do this with a workflow / custom code, but a roll-up property instead: Create calculation and rollup properties

You can create this property on the company record, let it calculate the average of the associated contact records in that particular field and define a condition.

This is a far superior approach compared to workflows as it’s not prone to enrollment issues or code errors, and calculates in real-time.

Best regards!