Created
October 11, 2019 15:34
-
-
Save cgillis-aras/051bf7581ac7fcff440cf1fbdab7a373 to your computer and use it in GitHub Desktop.
Example of rolling up a property on the relationships to the parent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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