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.
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.
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?
LikeLike
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?
LikeLike
I didn't get the correct question, can you please explain in detail.
LikeLike
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
LikeLike
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.
LikeLike
Patrick – You sir. Just made my day.
LikeLike
Thanks for posting it here.
LikeLike
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.
LikeLike
Try this:function refreshIframe(name) { var webResourceControl = Xrm.Page.getControl(name); var src = webResourceControl.getSrc(); webResourceControl.setSrc(null); webResourceControl.setSrc(src);}
LikeLike
Thank you for commenting Navas, updated the post accordingly.
LikeLike
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
LikeLike
Are you able to solve the issue?
LikeLike
Thanx for the code.It works perfect
LikeLike
super its working
LikeLike
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.
LikeLike
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);}
LikeLike