Skip to main content
Dynamics 365 general forum
Suggested answer

Transition code to UCI

editSubscribe (0) ShareShare
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() != "") {;
   // 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() {
    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() != "") {

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.
  • Suggested answer
    Linn Zaw Win Profile Picture
    Linn Zaw Win 3,403 on at
    RE: Transition code to UCI

    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

  • Suggested answer
    RE: Transition code to UCI

    Hi Mbah,

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


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

    function ola(executionContext)
    //do stuff

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…


Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,066 Super User

Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans