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

Announcements

No record found.

News and Announcements icon
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
    Microsoft Employee 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 196 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 129

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans