Records in IFrame from N:N relationships

We had a custom entity “store” which had an N:N relation with contact entity. We had another custom entity named “visit” which had a lookup for “store” and an IFrame named contacts. We were required to display all the contacts which are related to the “store” record which was selected in the lookup field. We had written some javascript code in the OnLoad event of the form. We were able to get records when the “store” had 1:N relation with contact. But it was not working for N:N relation.

Below is the code snip in

if( crmForm.all.new_doorid.DataValue != null )

{

var DoorID = crmForm.all.new_doorid.DataValue[0].id.toString().replace(“{“, “”).replace(“}”, “”);

LinkGrid(“IFRAME_MattressSlots”, 10010, ‘new_new_door_new_mattressslot’, DoorID);

LinkGrid(“IFRAME_Contacts”, 10010, ‘new_new_door_contact’, DoorID);

LinkGrid(“IFRAME_PILLOWS”, 10010, ‘new_new_door_new_pillowsonsite’, DoorID);

}

At first we thought it was an issue with the parameters passed.  The parameters passed are very similar to one to many relationships, except the parameter called “RoleOrd”.

Let’s think the relationship between “Contact” and “Stores”. One contact can purchase products from multiple stores also one store may serve multiple contacts. The “RoleOrd” parameter must be set to “2” in case of an N:N relation. We did set this field but it did not work. We also changed the ObjectTypeId but it didn’t help either.

Finally we got our answer from one of the forums. The solution is that whenever we have an N:N relation, we are required to add a keyword “area” before the relation name, Which is passed as a parameter. So after this change the code looked like:

if( crmForm.all.new_doorid.DataValue != null )

{

var DoorID = crmForm.all.new_doorid.DataValue[0].id.toString().replace(“{“, “”).replace(“}”, “”);

LinkGrid(“IFRAME_MattressSlots”, 10010, ‘new_new_door_new_mattressslot’, DoorID);

LinkGrid(“IFRAME_Contacts”, 10010, ‘areanew_contact_new_door’, DoorID);

LinkGrid(“IFRAME_PILLOWS”, 10010, ‘new_new_door_new_pillowsonsite’, DoorID);

}

This time it worked.