Hello;
I am trying to put together java code for a custom command button that will open an email form in a dialog. The email form will have the Regarding field, To field (same as regarding) and Subject line pre-populated from the Lead form.
I am running into issues when I am trying to populate the email body with the content from an email template, but am having little success. The body of the email doesn't seem to be populating when the button is clicked. The fields seem to be populating as expected.
I found the id for the template (fd015726-c13a-ef11-840a-6045bd03efbc), but I require assistance with the java script. Can you please take a look at my code and let me know what I would need to chage/update in order to get the email body from the email template into the dialog form.
Please see my script below:
function OpenInitialEmail(primaryControl) {
let formContext = primaryControl; // primaryControl parameter of the command button is same as formContext and NOT executionContext
//Set template lookup parameter to pass to email
var emailtemplate = {
id: "fd015726-c13a-ef11-840a-6045bd03efbc",
objectId: formContext.data.entity.getId(),
objectTypeCode: "template"
};
// Define the data object with key-value pairs
var data = {
// Populating Subject line
"subject": "Interest in HOOPP",
// Populating Dynamics Generated column
"sksysdev_dynamicsgenerated": true,
// Populating To column with Lead
"to": [
{
"entityType": formContext.data.entity.getEntityName(),
"id": formContext.data.entity.getId(),
"name": formContext.data.entity.getPrimaryAttributeValue()
}
],
};
// Define the parameters for the form
var pageInput = {
pageType: "entityrecord",
entityName: "email", // Target entity logical name
data: data,
templateid: emailtemplate,
formId: "213b35fa-3e2e-ef11-840b-6045bd03efbc",
createFromEntity: {
"entityType": formContext.data.entity.getEntityName(),
"id": formContext.data.entity.getId(),
"name": formContext.data.entity.getPrimaryAttributeValue()
}
};
// Define the navigation options
var navOptions = {
target: 2,
height: {value: 80, unit:"%"},
width: {value: 70, unit:"%"},
position: 1
};
// Perform the navigation
Xrm.Navigation.navigateTo(pageInput, navOptions).then(
function success(result) {
// Called when the dialog closes
},
function (error) {
text: error.message;
}
);
}