web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Accessing form Library Javascript function from HTML web resource in Dynamics 365

gdas Profile Picture gdas 50,091 Moderator

Recently I have seen someone raised a Question in MS Dynamics CRM Community ( https://community.dynamics.com/365/f/761/t/305409 ), basically they did migration from Dynamics CRM 2016 to Dynamics 365. In earlier version we can directly access CRM form library JS function using “parent” from HTML web resource which has embedded inside the form, but now in Dynamics 365 9.0 onwards direct JS function access is no more supported.

Let say I have a JS function in my form library called “sayHello()”

function sayHello() {

alert(“Hello!!Welcome to parent method”);

}

In earlier version we used to call above parent function from HTML web Resource like below –

window.parent.Xrm.Page.sayHello();

But calling above way is not working in Dynamics 365 9.0 onward. The workaround is to assign the parent function in “Xrm.Page” object. Once  assign the function we can access the parent JavaScript function using “window.parent.Xrm.Page”

Here are the steps you need to follow –

Steps 1: –

In the parent JS library assign your function into Xrm.Page.

Xrm.Page.sayHelloFunction = sayHello();

Steps 2: –

Call method from the HTML web resource accessing Xrm.Page

window.parent.Xrm.Page.sayHelloFunction;

In summary, here is your parent JS library looks like –

parentLibrary.Js

function sayHello() {

alert(“Hello!!Welcome to parent method”);

}

Xrm.Page.sayHelloFunction = sayHello();

Here is the embedded HTML web resource where I am calling parent function.

TestHTMLWeb.html

<html>

<head>

<title></title>

<meta charset="utf-8">

function callParent()

{

window.parent.Xrm.Page.sayHelloFunction;

}

<meta>

<meta>

</head>

<body style="overflow-wrap: break-word;">

<input id="btntest" onclick="callParent()" type="button" value="Click Me">

</body>

</html>

Hope this helps.


This was originally posted here.

Comments

*This post is locked for comments