Sunday, January 12, 2014

MS CRM 2011/2013: Open new email form with To and Regarding fields prefilled

About a year ago I wrote small article how to open new activity form with Regarding field prefilled.
This week I had a similar task but this time I had to write a JavaScript that will open email form with To field prefilled. So here is the script that you can use:
function OpenEmail(recordid, recordtypecode) {
    var params = "pId=" + recordid + "&pName=&pType=" + recordtypecode;
    params += "&partyid=" + recordid + "&partyname=&partytype=" + recordtypecode;
    var url = "/main.aspx?etc=4202&pagetype=entityrecord&extraqs=" + encodeURIComponent(params);
    url = Xrm.Page.context.prependOrgName(url);
    window.open(url);
}

Here is sample of usage:

OpenEmail("c8576fa9-155e-e311-bbc5-6c3be5a8d218", 2);

This small JavaScript will open new email form with Regarding and To fields prefilled with contact with Id that equals to "c8576fa9-155e-e311-bbc5-6c3be5a8d218".

No comments:

Post a Comment