Relationship addition


I would like to know how to sum up the two elements in the relationship tab and display the result in the "Cost" property of the parent item ?

Thank you !

  • Hi Alber,

    This is an interesting question because it can be solved in a lot of different ways. :) You will need a custom method to handle the logic of adding the properties on the relationships together, but the bigger question is where to attach that custom method.

    If this cost property is simply for display purposes and you don't care about storing it, this would make the most sense to be attached as an onFormPopulated Form Event on the Form of your parent ItemType.

    However, if you're trying to store this value, it makes more sense to use a Server Event. This could be done using an onAfterUpdate event on the parent ItemType where you loop through the relationships and calculate the value every time the parent is updated. This solution works well because you only need one method and one event, but it also means the code will be called even when the cost does not change.

    Another approach would be to use onAfterUpdateonAfterAdd, and onAfterDelete server events on the relationship ItemType itself. Doing it this way, you would only have to get the current cost of the parent and add or subtract to it based on the value of the child. This approach means that the parent cost will only be calculated when it actually changes, but it also requires more code and more server events which will make it more difficult to maintain.

    For simplicity, I'd recommend taking the second approach of using an onAfterUpdate server event on the parent ItemType. I've included a Gist below that walks through a similar example using the standard Part ItemType. Note that the code I've provided is meant to serve as a demonstration only and should not be used as-is.


    Christopher Gillis

    Aras Labs Software Engineer

  • Hello,

    Thank you for your answer

    However, the struggle for me is to access an Item from the code. Which syntax / functions should I use ?

Reply Children