Thursday, January 10, 2013

MS CRM 2011: Open new activity form with ‘Regarding’ field prefilled

I had a task today to open new task form with Regarding field prefilled. Based on SDK description I tried to use following code to accomplish my task:

var params = {
    regardingobjectid: referenced record id,
    regardingobjectidtype: referenced record type name,
    regardingobjectidname: referenced record display name
};

Xrm.Utility.openEntityForm("task", null, params);

Unfortunately this code failed. I’ve started to look for some explanation and I found it in SDK at the same article I’ve mentioned before. Answer was that it is impossible to set values for partylists and regarding lookups.
I knew that this feature works for out of box buttons so I rechecked URL for activities that are created with OOB buttons and reworked code to following which worked without issues:

var params = {
    pId: referenced record id,
    pType: referenced record type code,
    pName: referenced record display name
};

Xrm.Utility.openEntityForm("task", null, params);