Hi Michelle,
I think the issue you're running into is related to updating the item within an onBeforeUpdate itself. You may be entering into an issue where each update of the item within the server event is triggering it's own onBeforeUpdate event.
I was able to work around this issue in a test environment by simplifying the sample of code provided. Within the onBeforeUpdate event, we already have access to the item we want to check the relationships on through the context item (
this). Additionally, we don't need to apply an edit since that will automatically take place once the onBeforeUpdate finishes. All that needs to be done is to set the property on
this before we return from the method. You can see the sample code that worked in my environment below.
// Fetch any relationships that may not exist in this context
this.fetchRelationships("ATEN_VPR_File");
Item relationships = this.getRelationships("ATEN_VPR_File");
// Get the count of the relationships
int count = relationships.getItemCount();
// Store the count in the property on the item
this.setProperty("_h_test", count.ToString());
// And let the apply that will be called after this onBeforeUpdate save that property to the database
return this;
Chris
Christopher Gillis
Aras Labs Software Engineer