web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Transition code to UCI

(0) ShareShare
ReportReport
Posted on by

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.
 ErrorEmailSend.PNG
Any help will be greatly appreciated.
I have the same question (0)
  • Suggested answer
    Miguel Lourenco Profile Picture
    on at

    Hi Mbah,

    Are you checking this to enable the executioncontext to be passed ?

    pastedimage1592815524549v1.png

    Also, you need to declare the function with the parameter like:

    function ola(executionContext)
    {
    //do stuff
    }

  • Suggested answer
    Linn Zaw Win Profile Picture
    3,407 on at

    If your onSend() function is a form ribbon, add the primaryControl CRM Parameter as mentioned in the blog post below and change your function to

    function onSend(primaryControl) {
    var formContext = primaryControl;
    // The rest of the script
    .................................
    .................................

    https://blog.magnetismsolutions.com/blog/alfwynjordan/2019/10/02/getting-dynamics-365-formcontext-from-ribbon-workbench

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 71 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

#2
BillurSamdancioglu Profile Picture

BillurSamdancioglu 55 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans