As you may know whether you have somewhat of a history in Web UI configuration, there are a couple obstacles to be capable to be allowed to run javascript if your IFRAME contains a page from a site that is different to the HTML page hosting the IFRAME. This so-called cross site scripting was a big problem in earlier browsers and security blocks added in to stop this being hijacked for nefarious purposes. To deal with this the form designer in CRM 4.0 has the option to switch this security on or off. Unfortunately this has its limitations and I found that the option did not have any effect on the script I was trying to run from the page in the IFRAME. In the end I had to create a virtual directory in IIS in the same website as CRM. The other part I had to watch for is that I used the URL from the root of the site, not the redirected path that the CRM application uses.

Once over that hurdle, I had a bit of a wrestle with Javascript and dragging it out of my brain at the same time! To explain what I was trying to do, I had two controls on the parent form to populate. No problem, I had the names of the attributes and CRM 4.0 has a nice way of naming fields and controls from the attribute names. Unfortunately I got an access denied error thrown by the script engine in the browser. By a process of trial and error I established that one control worked and the other did not. Not because of value types or anything, it was because one was a lookup and the other was a straight text field. Lookups need a different approach to accessing them, as they use an array as part of the matching to list setup.

Having established this, I dived in to the code in the Microsoft Dynamics CRM 4.0 SDK which is something like thus :

//Create an array to set as the DataValue for the lookup control.
var lookupData = new Array();
//Create an Object add to the array.
   var lookupItem= new Object();
//Set the id, typename, and name properties to the object. = '{1AAC1363-01A1-DB11-8432-0003FF9CE217}';
   lookupItem.typename = 'account'; = 'A Bike Store';
// Add the object to the array.
   lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
   crmForm.all.parentaccountid.DataValue = lookupData;

Fine, but what guid id is that and how was I going to find it out. Further searching established that it is the guid of the entity that is listed by the lookup. Finding this out was a bit of a hunt again. Firstly I found the name of the entity being looked up by checking the properties of the lookup on the parent form. This pointed me to the source entity. Then I navigated through settings to call up the entity. Doing this lined up a URL with the GUID on it - perfect. The typename was also shown on one of these property pages. I filled them all in, and it didn't work. I did some cursing of Javascript and started hunting again.

Much obliged, Help is valued.