Skip to main content
Dynamics 365 general forum
Suggested answer

Transition code to UCI

editSubscribe (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.
Categories:
  • 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
    .................................
    .................................

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

  • Suggested answer
    RE: Transition code to UCI

    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
    }

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…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 222,585 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans