Forum Discussion

Former_Member's avatar
Former_Member
Ideator I
9 years ago

permissions error when trying to create a relationship

Dear Community, I am new to Aras and am trying to create a relationship from a RelationshipType with the following code:
Innovator inn = this.getInnovator();
string ItemId = this.getID();
Item item = inn.getItemByKeyedName("GivenItem", "100013-001");
string itemfather = item.getID();
if(item == null)
{
return inn.newError("No given item found.");
}
else
{
Item relItem  = inn.newItem("GivenRelationship","add");
relItem.setProperty("source_id",ItemId);
relItem.setProperty("related_id",itemfather);
return relItem.apply();
}
return this;
The method runs onAfterAdd on a relationship ItemType server event. I do not know how to solve this error which comes with the apply() method: "You have insufficient permissions to perform 'add' operation." I am also looking for a way to retrieve the GivenItem item because we dont know its keyed name. What I want to do is to retrieve the Item of type OtherType which has a relation whith the item of type GivenItem (there will be only one each type). Is there a method which permits to get the only item of a given type? Best regards, Camille

19 Replies

  • Built in function may not have been the correct terminology, but basically instead of manually setting the properties you create a relationship object and use the functions to add it to the parent item. (this is my understanding of how this works and I could very well be incorrect) directly setting: parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); this.setProperty(“related_id”, childItem.getID()); I create the relationship object and invoke setRelatedItem & addRelationship, this way if any other housekeeping happens I am covered (I assume). docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item part.addRelationship(docRelationship); // here is the parent (source?) item
  • Built in function may not have been the correct terminology, but basically instead of manually setting the properties you create a relationship object and use the functions to add it to the parent item. (this is my understanding of how this works and I could very well be incorrect) directly setting:
    parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); this.setProperty(“related_id”, childItem.getID());
    I create the relationship object and invoke setRelatedItem & addRelationship, this way if any other housekeeping happens I am covered (I assume).
    docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item part.addRelationship(docRelationship); // here is the parent (source?) item
  • Built in function may not have been the correct terminology, but basically instead of manually setting the properties you create a relationship object and use the functions to add it to the parent item. (this is my understanding of how this works and I could very well be incorrect) directly setting: parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); this.setProperty(“related_id”, childItem.getID()); I create the relationship object and invoke setRelatedItem & addRelationship, this way if any other housekeeping happens I am covered (I assume). docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item part.addRelationship(docRelationship); // here is the parent (source?) item
  • Built in function may not have been the correct terminology, but basically instead of manually setting the properties you create a relationship object and use the functions to add it to the parent item. (this is my understanding of how this works and I could very well be incorrect) directly setting: parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); this.setProperty(“related_id”, childItem.getID()); I create the relationship object and invoke setRelatedItem & addRelationship, this way if any other housekeeping happens I am covered (I assume). docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item part.addRelationship(docRelationship); // here is the parent (source?) item
  • Built in function may not have been the correct terminology, but basically instead of manually setting the properties you create a relationship object and use the functions to add it to the parent item. (this is my understanding of how this works and I could very well be incorrect) directly setting: parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); this.setProperty(“related_id”, childItem.getID()); I create the relationship object and invoke setRelatedItem & addRelationship, this way if any other housekeeping happens I am covered (I assume). docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item part.addRelationship(docRelationship); // here is the parent (source?) item
  • Instead of setting the properties directly, like this:
    parentItem.setProperty(“id”,this.getProperty(“source_id”,””) ); thisItem.setProperty(“related_id”,item.getID());
    I created a relationship object, and set it's related item:
    docRelationship.setRelatedItem(cadDocument); // here is the linkage to the related item
    then added the relationship to the parent item with:
    part.addRelationship(docRelationship);
    I don't know if setting the ids directly is equal to using the relationship object, or if I am using it incorrectly. I was wondering the difference, if any.
  • Thank you for your answer DBardine, That would be great to have a comparison of those functions but as I can read, setRelatedItem and createRelatedItem will create the related_id property if it doesn't exist, which is not the case with setProperty I don't know about addRelationship I use createRelationship the same way as newItem Anyone with more info? Best regards
  • 1.MyMainItem.SetRelatedItem(myRelatedItem) takes an Item as single argument it will find(or create) the related_id property in MyMainItem and appends myRelatedItem to it 2.MyMainItem.CreateRelatedItem("myItemType","get") takes a type of item and an AML action as arguments it will find(or create) the related_id property in MyMainItem and appends : "<Item type='myItemType' action='get'/>"