When sending an outgoing email from D365 CE or crm, after user press send button to send an email, we have an onSend function that we use to append additional content to the email body before email is sent to recipient.
In web client, this used to work
function onSend() {
if (Xrm.Page.getAttribute('description').getValue() != null && Xrm.Page.getAttribute('description').getValue() != "") {
Xrm.Page.data.entity.addOnSave(addFeedbackLink);
}
// formContext.getControl("subject").setFocus();
}
But now with UCI, We changed the code since Xrm.Page has been or is being deprecated to this below and it no longer work, we are not sure how to get the execution context from this function.
function onSend() {
debugger;
if(!formContext || !executionContext)
{
alert("formContext/executionContext is null");
formContext = executionContext.getFormContext();
}
if(formContext != null && formContext.getControl("description") != null && formContext.getControl("subject") != null){
if (formContext.getControl("description").getAttribute().getValue() != null && formContext.getControl("description").getAttribute().getValue() != "") {
formContext.data.entity.addOnSave(addFeedbackLink);
}
formContext.getControl("subject").setFocus();
}
}
Not only, the alert pops up every time but execution context is null and we get an error executionContext is not defined.
Any help will be greatly appreciated.