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 !
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 onAfterUpdate, onAfterAdd, 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.
Aras Labs Software Engineer
If you're unfamiliar with querying in Aras Innovator, I'd recommend checking out our blog post which covers the basics of AML, our querying language. Once you have an idea of what the AML query should look like, you can then check out this blog post to see how you can build that same query in server code.