Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of rolling up a property on the relationships to the parent
/*
* NOTE: This code is a sample to demonstrate how to rollup one level of a relationship.
* It is has not been fully tested and should not be used in a production environment as-is.
*/
/* Query for item and relationships happens above */
parentPart = parentPart.apply();
// Get the relationships from your item
Item partBoms = parentPart.getRelationships("Part BOM");
// Add all of the costs of the related parts together
double totalCost = 0;
for (int i = 0; i < partBoms.getItemCount(); i++)
{
var partBom = partBoms.getItemByIndex(i);
var childPart = partBom.getRelatedItem();
// Quick validation so our parsing logic doesn't fail
string childCost = childPart.getProperty("cost", "");
if (!string.IsNullOrEmpty(childCost))
{
totalCost += double.Parse(childCost);
}
}
// Set the total cost on our parent part
parentPart.setProperty("cost", totalCost.ToString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.