How to add an IFrame for a N:N relationship in Dynamics CRM 4.0

This is a translation from this post I published in Spanish in elblogdeDynamicsCRM.com.

 

Sometimes we are asked to display a grid within a form that shows related records.  For instance, in order to see Addresses of an Account.

For doing so, there are already some good samples in Internet that we can take as reference, like this one by DynamicsCare, this one from Jim Wang and this one from Bill Owens..

Nevertheless, if we try to add a grid for a N:N relationship we could face up with the following error (generic error message):

image_thumb5

Actually, if we turn on DevErrors in web.config you will see a generic ‘Object reference is not set to an instance of an object…’ error.

 

This may be due to the following reasons:

 

1. Urls for N:N relationships need one additional parameter [roleOrd]. This parameter indicates ‘which side’ of the N:N relationship should be displayed, accepting as

far as I could see values ‘1’ and ‘2’. Use it this way: if for instance we have Accounts->Contacts relationship and we are  in the Accounts form, then roleIOrd=2.

 

2. The above by itself is not enough to make it work (at least in my case) but it was necessary to include the word ‘area’ before the name of the relationship for the parameter ‘tabSet’. For instance:

http://<myserver>/<myorganization>/sfa/accts/areas.aspx?oId={object guid}&oType=1&security=852023&tabSet=areanew_new_<myentityname>_account&roleOrd=2

 

So, if you need to include a grid within a form to show the records of a N:N relationship, remember this is pretty similar to the examples that are currently present in Internet and you need to add parameter roleOrd + the word ‘area’ before the name of the relationship.

 

Next, some javascript code as reference for OnLoad event in the main form:

function GetFrameSource(tabSet) {
if (crmForm.ObjectId != null) {
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet;
}
else {
return "about:blank";
}
}

var tmp = document.getElementById('nav<relationship_name>').onclick.toString();
tmp = tmp.substring(tmp.indexOf("'")+1, tmp.indexOf(";"));
var loadArea = tmp.substring(0, tmp.indexOf("'"));
var roleOrd = (tmp.indexOf("roleOrd") == -1) ? -1 : tmp.substring( tmp.indexOf("roleOrd"), tmp.lastIndexOf("'")).replace("\\x3d", "=");

crmForm.all.IFRAME_<iframe_name>.src = GetFrameSource("area<relationship_name>") + '&' + roleOrd;

….

 

Hope you find this useful,

 

PP [twitter: @pabloperalta]

No Comments