Geeks With Blogs
Oh my god ... not another MS CRM blog Guenter vs. MSCRM

CRM has a quite cool feature that can save you a lot of programming: URL addressable forms. If you want to let users create or update records, you can use the CRM standard forms. The only thing you have to do: open an new window with the specific URL. If you want to edit a record, you only have to append the id of the specific record. In edition you are able to manipulate every form field in the new window and pre-fill them. (I do not mention x-domain-scripting here).

If you want to manipulate lookup fields, you have to do this in a special way to make it work. I did not find it anywhere, so I will post here how to do it. Just look at the following JS snippet to figure out how. In the following example the source campaign of a new lead record is pre-filled:

var newwin;

// first you have to open an new window. call the following function from anywhere on your web page
function OpenNewLead()
{
 newwin=window.open('/sfa/leads/edit.aspx', 'newlead',
  'width=830,height=600,directories=no,menubar=no,resizable=yes,titlebar=no,toolbar=no');
    
 window.setTimeout("PreFillSourceCampaign()", 1000);
}

function PreFillSourceCampaign()
{
 if(!newwin.document.crmForm.all.campaignid.DataValue)
 {  
  var ar=new Array(1);
  ar[0]=new Object;   
  ar[0].id='{00000000-0000-0000-0000-000000000000}'; // fill in here the correct GUID of your object
  ar[0].type='4400'; // adapt the typecode for your entity type
  ar[0].name='My Campaign Name';   // adapt the correct object name
  newwin.document.crmForm.all.campaignid.DataValue=ar;
 }
 else
 {
  window.setTimeout("PreFillSourceCampaign()", 1000);
 }
}

P.S. I use window.setTimeout here to make sure the DOM of the new child window is loaded before I manipulate the field.

Have fun! :-)

Posted on Tuesday, April 18, 2006 10:05 AM | Back to top


Comments on this post: How to manipulate Lookup fields in CRM URL addressable forms from another window

# re: How to manipulate Lookup fields in CRM URL addressable forms from another window
Requesting Gravatar...
Hi Guenter,

If you are still tracking this: I need to copy the contents of some fields on the Quote form to some fields on the related Opportunity form on the onclose event of the Quote. I'd suspect this is simpler than manipulating lookup fields as you describe above. Can I use the same technique ? Do I have to open a new window with the Opp form, copy the values, save the Opp form and close the window ? Or can I do this 'silently' i.e. without showing the Opp form ? Can you maybe suggest some script ? Thanks
Left by nb0512 on Feb 27, 2008 4:25 AM

Your comment:
 (will show your gravatar)


Copyright © Guenter Wallnoefer | Powered by: GeeksWithBlogs.net