Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Transition code to UCI

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.
  • Suggested answer
    Linn Zaw Win Profile Picture
    Linn Zaw Win 3,405 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
    }

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans