While doing client work, I came across a problem with setting an IFrame URL dynamically. The underlying issue was that the sandbox instance is on v8 of Dynamics 365 and production is on v9 of Dynamics 365. The reason for this was because this client was setup around the time that Microsoft rolled out v9. Anyways, JavaScript that I wrote to dynamically set the URL of the IFrame wasn't working in the v9 instance. This was because of changes that Microsoft made to how IFrames are loaded on the form and also changes to JavaScript.
Here is my v8 setup:
Here is my v9 setup:
As you can see in my v9 code I have to pass in the execution context so I can create the form context. To do that you have to check the box next to, "Pass execution context as first parameter" when adding the JavaScript to the form.
Microsoft has not yet deprecated Xrm.Page yet but it is coming, so it is best to plan for it. Here are some important links I used when solving my problem of the JavaScript not running:
Important Change (deprecations) coming
OnReadyStateComplete
Execution Context
Form Context
Walkthrough: Write your first client script
Client API Reference
Here is my v8 setup:
- JavaScript runs OnLoad of contact form. This works because of how IFrames are loaded in v8. You can also run it on either a tab change (hide / show) or OnReadyStateComplete event of the IFrame. Depending on your setup you will need to choose which is best for you. For me in this case it was the OnLoad event.
- Here is the JavaScript:
function OnLoad()
{
//Get memberid
var value = Xrm.Page.data.entity.attributes.get("new_memberid").getValue();
//Get the default URL for the IFRAME, which includes the
// query string parameters
var IFrame = Xrm.Page.ui.controls.get("IFRAME_NAMEofIFRAME");
var Url = IFrame.getSrc();
//Append the parameters to the new page URL
newTarget = Url + "history?member=" + value;
// Use the setSrc method so that the IFRAME uses the
// new page with the existing parameters
IFrame.setSrc(newTarget);
}
Here is my v9 setup:
- JavaScript runs on OnReadyStateComplete event of the IFrame. I had to add extra code to prevent constant refresh of the IFrame. This is because on this event every time we update the URL if causes the OnReadyStateComplete event to fire. To prevent this we have to use an If/Else so we only update the URL if it hasn't been updated yet.
- Here is the JavaScript:
function OnReadyStateComplete(executionContext)
{
var formContext = executionContext.getFormContext();
var value = formContext.getAttribute("new_memberid").getValue();
//Get the default URL for the IFRAME, which includes the
// query string parameters
var IFrame = formContext.ui.controls.get("IFRAME_NAMEofIFRAME");
var Url = IFrame.getSrc();
var newTarget = "";
//Append the parameters to the new page URL
if(Url.includes(value))
{
newTarget = Url;
}
else
{
newTarget = Url + "history?member=" + value;
// Use the setSrc method so that the IFRAME uses the
// new page with the existing parameters
IFrame.setSrc(newTarget);
}
}
As you can see in my v9 code I have to pass in the execution context so I can create the form context. To do that you have to check the box next to, "Pass execution context as first parameter" when adding the JavaScript to the form.
Microsoft has not yet deprecated Xrm.Page yet but it is coming, so it is best to plan for it. Here are some important links I used when solving my problem of the JavaScript not running:
Important Change (deprecations) coming
OnReadyStateComplete
Execution Context
Form Context
Walkthrough: Write your first client script
Client API Reference
Excellent post, thanks for this. I gathered lots of information from this and I am happy about it. Do share more updates.
ReplyDeleteMicrosoft Dynamics crm Training in Chennai
Microsoft Dynamics Training
Microsoft crm Training
Hacking course in Chennai
Tally course in Chennai
PHP Training in Chennai
Web Designing Training in Chennai
Microsoft Dynamics crm Training in Anna Nagar
Microsoft Dynamics crm Training in Vadapalani
Microsoft Dynamics crm Training in Thiruvanmiyur
I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.
ReplyDeleteCRM with Invoicing
There are a few apparatuses where you can get even data on inbound connections and outbound connections, yet in this article we will concentrate on Spam Score. access the darknet
ReplyDelete