Hi team!
I need to create a property that aggregates the sum of another field, for example: I have two different records in a custom object that have the same identical property, and these two records have a value property, I need to add this value, aggregating by this equal field, the only way I can imagine this being done is through Python or Node.js code, but I have no idea where to go next
Does anyone have an example of how to do this?
Practical example:
I need the result of this code to be the sum of the record’s tpv based on the group property.
example:
I have 100 records in a certain object in HubSpot, these records are unique, in this object there is a property called group, where I can have two different records and that the group property is equal, I need that in these cases where the group property is equal the tpv value is summed (aggregated).
example here, in this case for this tester it should be 0.0 + 22.43 = 22.43, this for the entire object base
an example of what to expect
@CarolineFscs - interesting problem!
Just to be clear - for every new custom object record created, it would be bnecessary to loop over all existing records of that object type and sum the ‘tpv’ values for every instance where the group property value on the new record matches the group value on the new record.
When you have that new sum value for the whole set of cusom objects, it would be necessary to go back through all records and patch the new summed tpv value to the new record and each rother ecord where the group value is a match to the new record.
Did I paraphrase the challenge correctly? If so, I believe this likely requires a custom coded workflow step (or two) using Ops Hub Pro. I had originally wondered if it could be accomplished with a formula property, but I don’t think that can be done if there are multiple different possible group values.
I hope this is helpful
Steve
@SteveHTM In this case, it would be to create a new property, and copy the output of this code to that property.
Do you have any examples of custom code for this problem?
@CarolineFscs - that could be done I guess, but wouldn’t you face the problem that the list of properties for the custom object would grow without bounds (at least as many properties as unique values of the group property anyhow)? And then, if I summarized the algorithm correctly, you would need to write your sum value to a new property on each of the relevent records.
The code to add a property is relatively simple - an API call based around
/crm/v3/properties/{objectType}
I probably do have some basic python code for this - but given that the number of custom object records could grow quite large (and considering API call limits), I think that some batch APIs may be more efficient than code I already have.
Steve