RE: Customize Email Sender
Hi DeVoe1,
When you reply one email, it will open new email form and some fields will be filled. One field is named Parent Activity Id, which is OOB field and it stores id of the email that you need response.
In my example, I set a queue with shared email address.
Here are steps.
1. Add Parent Activity Id field to the form, which can make us get id of the received email easily.
2.Retrieve received email with ‘Parent Activity Id’ value to get ‘to’ field value.
3. Retrieve queue with the email address(to field) to get the queue id, name and type.
4.Replace parameters with dynamics value in js:
function UpdateFromField(executionContext) {
var formContext = executionContext.getFormContext();
var lookup = formContext.getAttribute("parentactivityid").getValue(); // recevied email lookup(Parent Activity Id)
if (lookup != null) {
var receviedid = lookup[0].id.slice(1, -1);
Xrm.WebApi.online.retrieveRecord("email", "" receviedid "", "?$select=torecipients").then( //get recevied email 'to' field value(email address)
function success(result) {
var torecipients = result["torecipients"];
torecipients = torecipients.replace(";","");//remove ; symbol
if (torecipients == "testsharedmailbox@crmxxxxxx.onmicrosoft.com") //only shared email address can update
{
Xrm.WebApi.online.retrieveMultipleRecords("queue", "?$select=name,queueid,queuetypecode&$filter=emailaddress eq 'testsharedmailbox@crmxxxxxx.onmicrosoft.com'").then(
function success(results) {
for (var i = 0; i < results.entities.length; i ) {
var name = results.entities[i]["name"];
var queueid = results.entities[i]["queueid"];
//update from field
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = queueid;
lookup[0].name = name;
lookup[0].entityType = "queue";
formContext.getAttribute("from").setValue(lookup);//set the lookup value finally
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
}
5.Test.
(1) it is received email:
(2) when i click reply button:
Note: You can try to use CRM Rest Builder tool, which can create request easily.
Download page: https://github.com/jlattimer/CRMRESTBuilder
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.