Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

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

Posted on by 150

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?

  • ishraqiyun77 Profile Picture
    ishraqiyun77 150 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
    LeoAlt 16,329 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

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans