Auto populate the “to” field of custom entity in Dynamics 365 CRM

To auto populate “to” field email form, in Dynamics CRM. For custom entity, it is not available by default. You need to write JS code to achieve this. Below code is all you need

function setToPartyList(executionContext){
    var formContext = executionContext.getFormContext()
    if(formContext.getAttribute("regardingobjectid").getValue() != null) {
        var regardingidname = formContext.getAttribute("regardingobjectid").getValue()[0].name;
        var regardingId = formContext.getAttribute("regardingobjectid").getValue()[0].id;

        // Create new array
        var partlist = new Array();
        partlist[0] = new Object();
        partlist[0].id = regardingId;
        partlist[0].name =  regardingidname;
        partlist[0].entityType = "lib_librarytracker";
        formContext.getAttribute("to").setValue(partlist);
    }
  };
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s