This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - How to configure Reverse Relationship between 2 itemtype

DK@Aras - Wednesday, February 5, 2014 11:42 PM:

Hi,

I want to create a relationship between 2 itemtype (A and B) with below scenario and need help to configure/develop it.

Scenario:

If user create a "A1" Item and related it with "B1" item in the "relationship tab" then in "B1" item it should display that it is related with "A1" item if you go to "B" itemtype and search for "B1" item.

I would like to show this association as a field on B itemtype form.

Is there a way to configure it using Aras or i have to write custom code for it. Any guidance and sample code is appreciated.

NOTE: here A1 and B1 are item of itemtype A and Itemtype B respectively.

 

Thanks in Advance!!

 



Harsha - Thursday, February 13, 2014 1:05 AM:

Hi DK,

I.Check CAD Document's form, there is a HTML field which displays the Part Number to which that CAD Document is added as a related Item.

II.If 'B1' is added as related Item to Multiple A items. If B1 added to A1,A2  then please check 'Vendors' tab of Part Item which displays list of vendors who is supplying the Part. But this is just a view . No actions are allowed here.

III.Or you can create a new Relarionship to ItemType B and a Server Method on ItemType A which gets the related Bs to A first and adds the Item of A to the new Relationship.

Eg: On A's OnBeforeAdd and OnBeforeUpdate.

Innovator inn = this.getInnovator();

Item Bs = inn.newItem("B","get");

Bs.setAttribute("where","[B].id in(select related_id from [AtoBRel] where source_id = '"+this.getID+")' ");

Item results = Bs.Apply();

int count = results.getItemCount();

for(int i=0;i<count;i++){

Item newRel= inn.newItem("NewRel","add") ; '//Newly added relationship to B
newRel.setProperty("source_id",results.getItemByIndex(i).getProperty("id"));
newRel.setProperty("related_id",this.getID) ;

newRel = newRel.Apply();

}

Note: Duplication may happen with this kind of procedures. So,you have to take care to not add duplicate Items.

Reply me if any issues, Harsha

 



DK@Aras - Wednesday, February 19, 2014 2:11 AM:

Hi Harsha,

Thank you so much !!

I have tried #1, mentioned above and worked for me.

Thank you again !!