Forum Discussion
Meismart
9 years agoIdeator I
toto
I believe you are trying to add a child relationship to an item using on-after add.
Something to consider is what are you doing if there is already a related item? i.e. this.getProperty("related_id","") != ""
The following is not tested, but is should set you in the right direction:
- If you have a relationship item, then you can use this.getProperty("source_id","") ; to get the id of the parent Item.
- To get the parent item, you can use: Item parentItem = inn.newItem("[Parent ItemType]","get"); parentItem.setProperty("id",this.getProperty("source_id","") ); parentItem = parentItem.apply();
- To add a child item: Item childItem = inn.newItem("[Child ItemType]","add"); childItem = childItem.apply(); //Remember to set the related id of this Item thisItem = inn.newItem(this.getType(),"edit"); thisItem.setAttribute("where","id=" + this.getID() +"'"); thisItem.setProperty("related_id",item.getID()); thisItem = thisItem.apply();
- Set the RelatedID on the context Item. this.setProperty("related_id", childItem.getID());
- Set the Keyed Name this.setPropertyAttribute("related_id","keyed_name='" + item.getProperty("keyed_name","") + "'");