web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 (0)
  • ishraqiyun77 Profile Picture
    154 on at
    RE: executionContext for JS and HTML web resource that should be triggered by onclick

    That did the trick! Thanks!

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: executionContext for JS and HTML web resource that should be triggered by onclick

    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

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 394

#2
Nimsara Jayathilaka. Profile Picture

Nimsara Jayathilaka. 123

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 106 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans