Monday, April 16, 2012

Accessing HTML web resource funcitons from entity Form in CRM 2011

I found this piece of code really handy. If you have a web resource that you place inside a form and if you want to manipulate the html within that html web resource you can do it.
Xrm.Page.getControl("WebResource_YourWebResource").getObject().contentWindow.window.WebResourceFunction
The function WebResourceFunction sits inside the HTML web resource and can do anything.
An example of how I used it was to call the HTML web resource function on the onchange event of a lookup and display something different for different values in the lookup box. Oh and yes you can pass parameters to the function as well.
To be fair, I found this technique on some other blog, but I can reference it since I lost the address and can't find it any more.
Happy Coding!

2 comments:

  1. hi Atif,
    thanks for your post. but i created a checkbox in HTML WebResource. I want to retrieve the selected values in checkbox and place those in a CRM2011 Entity field

    ReplyDelete
  2. Hi Atif,
    I tried to access function in html web resource from form JS like you described . It works but sometimes it throws an error that Object doesn’t support property or method ‘getScript’. Here getScript is a function in html web resource.
    I used following script
    var data = Xrm.Page.getControl(id).getObject().contentWindow.window.getScript();
    Any idea of the issue.

    Thanks Pradeep

    ReplyDelete