Error: Object does not support property or method “setSrc” in Dynamics CRM outlook client

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
Recently my customer integrated their Dynamics CRM with outlook client. Everything was going fine until they reported that reported that when the CRM fields for Email entity are loading in Outlook client, they are getting the below error.
image
Ok. So first things first. Where and why is setSrc method is being used?
Well, my customer had a web resource on the email form and they were dynamically setting the URL of the webresource using the below code.
function FormLoad(){
var webResource = Xrm.Page.getControl(“<WebResourceName>”);
if(webResource != null){
webResource.setSrc(Xrm.Page.context.getClientUrl() + “<path to webresource>”);
}

}
The code seemed to work perfectly fine in Web Client. However in Outlook client it started throwing the above error.
So instead of setting the source of the Web Resource control, we decided to use the getObject method of the WebResource control. The getObject method returns the HTML IFrame element representing the webresource control.
And as many of you might be thinking whether it is supported to use this or not, the good news is, it is a documented method. So you can use it. And to my surprise, many were not aware of the same and was not sure whether it is supported or not.
And the last step would be to set the source of the IFrame element using its src attribute. To make the code more generic, the below code would work across your web as well as outlook clients.
var webResource = Xrm.Page.getControl(“<WebResourceName>”);
if (webResource != null) {
try{
webResource.setSrc(Xrm.Page.context.getClientUrl() + “<path to web resource>”);

catch(error){
var iframeObject = webResource.getObject();
iframeObject.src = Xrm.Page.context.getClientUrl() + “<path to web resource>”;
}
}

Off course you can be more explicit in the catch for the specific errors but this is just a demo code and you can modify as per your needs.
Hope this helps.
Debajit Dutta
(Visit our products page – http://www.xrmforyou.com/products-1.html to know more about our offerings)


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading