CRM Crate

Programmatically update source URL of iFrames in Dynamics 365

We will learn to programmatically update the source URL of iFrames in Dynamics 365. Before we start, make sure to subscribe to CRM Crate so that you stay up-to-date in field of Dynamics 365.

Programmatically update source URL of iFrames in Dynamics 365

What are iFrames in Dynamics 365 form?

iFrame controls the embed content from another location in pages by using an HTML IFRAME element. You can use an iFrame to render the contents from another website in a form.

Click on the given link to learn – https://www.crmcrate.com/form-customization/what-are-iframes-how-to-add-iframe-in-form-display-website-webpage/

Using client API to update the source URL of iFrames in Dynamics 365.

We will use the setSrc client API reference to dynamically update the source URL in a single iFrame.

formContext.getControl(arg).setSrc(string);

Sets the URL to be displayed in an IFRAME or web resource.
NameTypeRequiredDescription
stringStringYesThe URL.

JavaScript snippet code for updating the source URL of iFrames –

For our demonstration, we will update the iFrame source URL according to the vaue in field “Web Page Type”.

The below JavaScript function is triggered during the “OnChange” event of field.
Note: – Replace the argument “IFRAME_webpage” with the schema name of your form iFrame.

//CRM Crate - JavaScript Snippet
function CallMethod (executionContext) {

//Reading Attribute Value From The Form.
var formContext = executionContext.getFormContext();
var Input = formContext.getAttribute("cc_webpagetype").getValue();
if(Input == 1)
{

//Using setScr client API.
formContext.getControl("IFRAME_webpage").setSrc("https://www.crmcrate.com/");
}
else if(Input == 2)
{
//Using setScr client API.
formContext.getControl("IFRAME_webpage").setSrc("https://www.britannica.com/place/Mercury-planet");
}
else if(Input == 3)
{
//Using setScr client API.
formContext.getControl("IFRAME_webpage").setSrc("https://www.britannica.com/animal/guppy");
}
else if(Input == 4)
{
//Using setScr client API.
formContext.getControl("IFRAME_webpage").setSrc("https://www.britannica.com/animal/earthworm");
}
}

Validating the result in Dynamics 365 form –

  • Navigate to Dynamics 365 entity for which the above JavaScript code has been deployed.
  • Trigger the JavaScript function and validate if the source URL in the iFrame gets updated automatically.

Thus we learned to programmatically update source URL of iFrames in Dynamics 365.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.