Forum Discussion
The Method this.setProperty("related_id",idOfrelatedItem) is not the problem here,the problem is 'this' is the context item returned to the user, not the item to be saved.
Assuming that "this" is a single item, or you will have to loop for each item, you can use:
if (this.getProperty("related_id","") == "")
{
Item editItem = innovator.newItem("ItemType","get");
editItem.setProperty("id",this.getProperty("id",""));
editItem =editItem.apply();
if (editItem.getItemcount() == 1)
{
editItem.setAction("edit");
editItem.setProperty("related_id",idOfrelatedItem);
editItem = editItem .apply()
}
}
This should update the item, but I believe it will trigger a new onAfterUpdate Event, so make sure you check for the presence of the related-property and idOfrelatedItem and only perform the update once.