# Workflow with Custom Code

**URL:** <https://community.hubspot.com/t/workflow-with-custom-code/133081>\
**Category:** Data Hub\
**Tags:** workflow-extension\
**Created:** [May 21, 2025, 6:29am UTC](https://community.hubspot.com/t/workflow-with-custom-code/133081 "2025-05-21T06:29:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manasa\_V](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@Manasa\_V](https://community.hubspot.com/u/Manasa_V)\
**Post date:** [May 21, 2025, 6:29am UTC](https://community.hubspot.com/t/workflow-with-custom-code/133081/1 "2025-05-21T06:29:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![karstenkoehler](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karstenkoehler/32/68554_2.png) [@karstenkoehler](https://community.hubspot.com/u/karstenkoehler)\
**Post date:** [May 21, 2025, 6:31am UTC](https://community.hubspot.com/t/workflow-with-custom-code/133081/2 "2025-05-21T06:31:31Z")

</div>

Hi [@Manasa\_V](https://community.hubspot.com/t5/user/viewprofilepage/user-id/825978),

I wouldn’t do this with a workflow / custom code, but a roll-up property instead: [Create calculation and rollup properties](https://knowledge.hubspot.com/properties/create-calculation-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!
