Showing posts with label Default TO Values in Email. Show all posts
Showing posts with label Default TO Values in Email. Show all posts

Thursday, May 26, 2016

How to set the From and To Default values in Email in MS CRM

function RetrieveTOfromCASE() {
    var regardingObject = Xrm.Page.getAttribute("regardingobjectid");
    if (regardingObject.getValue() != null) {
        //SDK.REST.retrieveRecord(guid,entityname,select query,null,successcallback,errorcallback);
        SDK.REST.retrieveRecord(regardingObject.getValue()[0].id, "Incident", "Title,ContactId", null, successRetrieveEmail, errorHandler);
        
    }
}

function DefaultFROMandTO(GUID, NAME, LOGICALNAME) {
    //Set From Value
    if (Xrm.Page.ui.getFormType() == 1) {
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = "GUID";
        lookupValue[0].name = "NAME(Contact/User/Queue)";
        lookupValue[0].entityType = "ENTITYNAME(Contact/User/Queue)";
        Xrm.Page.getAttribute('from').setValue(lookupValue);

        //Set To Value
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = GUID;
        lookupValue[0].name = NAME;
        lookupValue[0].entityType = LOGICALNAME;
        Xrm.Page.getAttribute("to").setValue(lookupValue);
    }
}

var successRetrieveEmail = function (results) {
    DefaultTO(results.ContactId.Id, results.ContactId.Name, results.ContactId.LogicalName);
}

function errorHandler(error) {
}

//You need to add CRMSDK for this to work