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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

executionContext for JS and HTML web resource that should be triggered by onclick

(0) ShareShare
ReportReport
Posted on by 154

Basically, trying to execute an on-demand workflow when a button is clicked.

HTML

pastedimage1570485932739v1.png

JS

pastedimage1570487504778v2.png

There are a couple issues I've run into:

  1. Passing executionContext as a parameter in the HTML results in undefined
  2. Removing it does call the JS function, but then executionContext is still undefined--need to pass executionContext as first parameter
  3. Add the JS to the form properties under Form Libraries and then under Event Handlers so I can add the "pass executionContext as first paramater"--this results in "Cannot read property 'getFormContext' of undefined"
  4. Also, the HTML web resource doesn't show as Control under Event Handlers, so it is currenly OnLoad which causes an error when the form loads

So how should I be setting this up?

I have the same question (1)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    We could not get "executionContext" in html web resource directly.

    From your code I saw that you just want to get the value of "org_productbuyerid" field, so I suggest that you could follow my steps.

    For example I want to get the form field "Name" value in html web resource.

    I used the following code.

    var value2window.parent.Xrm.Page.getAttribute("new_name").getValue()

    pastedimage1570504752136v2.png

    Although Microsoft has announced that it is abandoning this approach "Xrm.page", However, they did not say that it should not be used in the form, which is the most appropriate method at present.

    BTW, if your field "productbuyerid" is a look up field, you need to get its id by this code:

    var buyer=formContext.getAttribute("productbuyerid").getValue();
    var buyerid=buyer[0].id;

    Hope it helps.

    Best Regards,

    Leo

  • ishraqiyun77 Profile Picture
    154 on at

    That did the trick! Thanks!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 47 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans