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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Unable to call a funct...
Power Apps
Unanswered

Unable to call a function in a HTML webresource

(0) ShareShare
ReportReport
Posted on by 636

I want to pass formcontext to a html WebEesource, so that it can update a few fields in a model driven form.

Unfortunately in my TypeScript, it is none too happy with .getContentWindow() as in it is not available. So am I missing a type or need to do a magic cast.?

 

Also this snippet won't know about the JavaScript functions in the Html WebResource so that is also an issue to solve🤔.

 

 

 

function onFormLoad(executionContext : Xrm.Events.EventContext)
{
 
 const formContext = executionContext.getFormContext();
 const webResourceName = "myproj_lookup.html"; 

 let webResourceControl = formContext.getControl<(webResourceName);
 
 // add a bit fo debugging code 
 let globalContext = Xrm.Utility.getGlobalContext();
 let webResourceUrl = globalContext.getWebResourceUrl(webResourceName);
 if (webResourceUrl)
 {
 // this shows the actual url
 console.log("Web Resource Url: " + webResourceUrl);
 
 } 
 
 if (webResourceControl) {
 webResourceControl.getContentWindow().then(
 function(contentWindow) {
 // Call your function to pass Xrm and formContext
 contentWindow.setClientApiContext(Xrm, formContext);
 
 });
 }
 else
 {
 // this what I am seeing :-(
 console.log("Web Resource not found") 
 }
 

 }

 

 

 

 

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    Hello,

    Try to get your control using the code similar to the following:

    let webResourceControl = formContext.getControl<Xrm.Controls.FramedControl>(webResourceName);
  • westerdaled Profile Picture
    636 on at

    Hi @a33ik 

     

    Thanks for replying. Yes, that gets me  getContentWIndow()

     

      with 

     

     contentWindow.setClientApiContext(Xrm, formContext);

     

     

    Do I need to add a myhtmlWidgetHelper.js to the form load event and  include the reference to this file in the widget.html .  I think one of my colleagues might have done this already ( he is a bit wiley 🥹) ,as he seems to have got the html widget to reference the parent form and so update the form fields.  I haven't had a chance to push the latest changes in our repo.  I do see other uses, if we can figure out how I can  interact with the html web resources, in both directions. 

     

     

     

     

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    The following post shows on how you can organize communication from embedded html to parent form through context - https://carldesouza.com/how-to-use-formcontext-in-a-web-resource-in-dynamics-365-power-apps/

    If you want to organize communication from form script to HTML there will be a different way of doing it - https://dreamingincrm.com/2015/11/23/using-window-postmessage-to-interact-with-iframe-in-crm-form/

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard