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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Calling form Java Script function from HTML button

(0) ShareShare
ReportReport
Posted on by

Hi 

I have an HTML button on a form, I want to call a form javascript function on button click. This function has confirm dialog. When I click on the button nothing happening. Below is the code, we are on onprem V8.2. Based on user response I want to update a field. where I am doing wrong? 

<html>
<head>
<script type="text/jscript">
function callfsENotification()
{
window.parent.Xrm.Page.fsENotification();
}
</script>
<meta charset="utf-8">
</head>
<body>
<button onclick="callfsENotification()" type="button">Send Email Notification</button>
</body>
</html>

function fsENotification()
{
Xrm.Utility.confirmDialog("Are you sure you want to send Email Notification", function(){ alert("yes"); },function(){alert("No");});
}

I have the same question (0)
  • SergioMarques Profile Picture
    on at

    Hi Krish,

    Is there any specific reason why you want to call to a function in the form JS?

    My suggestion is that you provide your iframe the Dynamics context, and avoid creating the dependency to the form JS.

    You can do this by adding the reference for ClientGlobalContext.js.aspx in the header of the HTML.

    More information here: docs.microsoft.com/.../getglobalcontext-clientglobalcontext.js.aspx

    To update the field on the form, you can then use the parent.Xrm.Page method.

    So your code would look something like (as an example):

    <html>

    <head>

    // the relative path here will depend on the context. I recommend you look to the doc linked above to know what is the correct way of calling this JS

    <script src="../ClientGlobalContext.js.aspx" type="text/javascript" ></script>

    <script type="text/jscript">

    function callfsENotification()

    {

    Xrm.Utility.confirmDialog("Are you sure you want to send Email Notification", function(){ alert("yes");

    parent.Xrm.Page.getAttribute("...").setValue(true);

    },function(){alert("No");});

    }

    </script>

    <meta charset="utf-8">

    </head>

    <body>

    <button onclick="callfsENotification()" type="button">Send Email Notification</button>

    </body>

    </html>

  • NKC Profile Picture
    on at

    Thanks for your reply. I used below script working fine.

    <html><head>

    <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

    <script type="text/jscript">

    function callfsENotification()

    {

    //debugger;

    window.parent.Xrm.Page.data.save();

    Xrm.Utility.confirmDialog("Are you sure you want to send Email Notification", function(){

    var sendEmail = window.parent.Xrm.Page.getAttribute("emailtrigger");

    if (sendEmail.getValue() != true)

            {

    //trigger the workflow by setting this value to true

    sendEmail.setValue(true);

           window.parent.Xrm.Page.data.save();

    }window.parent.Xrm.Page.getAttribute("emailtrigger").setSubmitMode("always");

           window.parent.Xrm.Page.data.save();},function(){return;});

    }

    </script>

    <meta charset="utf-8">

    <meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta></head>

    <body onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;">

    <button onclick="callfsENotification()" type="button">Send Email Notification</button>

    </body></html>

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 171 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 83

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans