Refreshing the Web Resource in CRM 2013/2015/2016

Hi,

We are using a HTML webresource to show some the attribute values of the CRM record on the entity form.

In CRM 2011, when ever we save the record the form used to reload and webresource also refreshes and get the latest data. But in CRM 2013 and later, on the save of the record the form won’t reload and as a result the values on the HTML resources were not getting refreshed.

The solution is to refresh the webresource using JavaScript on the Save Event of the form.

function refreshHTMLWebResource() {
    var webResourceControl = Xrm.Page.getControl(“WebresourceName);
    var src = webResourceControl.getSrc();
    webResourceControl.setSrc(null);
    webResourceControl.setSrc(src);


}

If you are on Dynamics 365, check this link for refreshing Iframe.


Hope this helps.

Happy CRM’ing
Gopinath.

16 thoughts on “Refreshing the Web Resource in CRM 2013/2015/2016

  1. Thomas August 25, 2015 / 1:41 pm

    Thanks. But on CRM 2015, this technique doesn't work anymore for me. when you need the record id (by Xrm.Page.data.entity.getId()), it only works with a setTimeout. Do you know an another way to get the record id in the OnSave handler?

    Like

  2. Thomas August 25, 2015 / 1:41 pm

    Thanks. But on CRM 2015, this technique doesn't work anymore for me. when you need the record id (by Xrm.Page.data.entity.getId()), it only works with a setTimeout. Do you know an another way to get the record id in the OnSave handler?

    Like

  3. Gopinath August 25, 2015 / 2:50 pm

    I didn't get the correct question, can you please explain in detail.

    Like

  4. Thomas August 26, 2015 / 7:53 am

    If you create a new record, and onsave you want to refresh your webresource. If your webresource needs to access Xrm.Page.data.entity.getId(), on CRM 7.0 it will return \”\”. There are 2 ways to fix this, setTimeOut in the onsave handler (-> not clean), add modified on on the form and onChange of this field, apply your code, in the onChange handler I have access to Xrm.Page.data.entity.getId() without having to use a setTimeOut

    Like

  5. Unknown February 19, 2016 / 3:34 pm

    I found in CRM 2015 that if you modify the string returned by the getSrc by adding a dummy parameter, then the setSrc will force a refresh of the HTML web resource: var webResourceControl = Xrm.Page.ui.controls.get(WebResourceNm); var websrc = webResourceControl.getSrc(); websrc = websrc + \”%26reload%3dyes\”; webResourceControl.setSrc(websrc);This works from the onchange event of a field in the parent form.

    Like

  6. Anand Kumar May 16, 2016 / 12:22 pm

    Hi Patrick Bodayle,This is a clean solution.In our case we have Silverlight webresource on entity form which needs to be refreshed on form save. We have used the above logic but it dint refresh. Andy idea here to guide.Thank you.

    Like

  7. Gareeb Navas July 20, 2016 / 5:08 pm

    Try this:function refreshIframe(name) { var webResourceControl = Xrm.Page.getControl(name); var src = webResourceControl.getSrc(); webResourceControl.setSrc(null); webResourceControl.setSrc(src);}

    Like

  8. Gopinath July 20, 2016 / 5:18 pm

    Thank you for commenting Navas, updated the post accordingly.

    Like

  9. Unknown September 20, 2016 / 9:09 am

    we tried to refresh the webresource using both ways setSrc(null) – setSrc(getSrc) or add new parameter to src. However we cannot then save the record.Error:Can't execute code from a freed scriptPlease help

    Like

  10. Unknown November 22, 2016 / 2:58 am

    Are you able to solve the issue?

    Like

  11. balu October 28, 2017 / 4:09 am

    Hey Hi, I have a similar requirement, please help me out.I have a customl html page on a form. If entity is updated then plugin will fired ,and it will calls the webservice and gets the data, through plugin creating the new records. This new records, I have to stamp on the html grid, without refreshing the crm form.When page is refreshed ,its html querying crm and stamping the data, but at a time plugin exexution completez,its not binding the data, everytime aftr plugin execution ,once refresh its load otherwise its not loading.

    Like

  12. Stephanie November 3, 2017 / 8:39 pm

    I would like to use this for refreshing a webresource that we have in the header, particularly the CRM2013 Horizontal Headers HTML. Does anyone know if it can be done? I am currently trying the below, but I am told it is undefined as the error.function refreshHTMLWebResource() { var webResourceControl = Xrm.Page.getControl(\”header_Webresource_Name\”); var src = webResourceControl.getSrc(); webResourceControl.setSrc(null); webResourceControl.setSrc(src);}

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s