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 :
Microsoft Dynamics CRM (Archived)

How to create button and trigger event onclik on button using javascript in Dynamics 365 crm

(0) ShareShare
ReportReport
Posted on by 775

Hello,

How can i create a button on entity form and also trigger event onclick on button using jscript

thanx.

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    To add button you can use Ribbon Workbench. To trigger onclick you can define JavaScript action on your button's command.

  • kiran_rajput Profile Picture
    775 on at

    my script is,

    <!DOCTYPE html>

    <html lang="en-US">

    <head>

    <title>Metadata Demonstration</title>

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

    <script type="text/javascript">

    function startSample() {

    var select = document.getElementById("combobox");

    select.onchange = function () {

    var index = this.selectedIndex;

    var selected = this.options;

    var selectedValue= selected[index].text;

    window.parent.Xrm.Page.getAttribute("jobtitle").setValue(selectedValue);

    };

    function clickSave(){

    var Xrm = window.parent.Xrm;

    Xrm.Page.data.entity.addOnSave(function (context) {

       alert("Form was saved");

    });

    };

    }

    </script>

    </head>

    <body onload="startSample()">

    <select id="combobox">

    <option value="softwaredeveloper">Softvare Developer</option>

    <option value="consultant">Microsoft Dynamics CRM Consultant</option>

    <option value="busdeveloper">Business Developer</option>

    </select>

    <button onclick="clickSave()">

     Save</button>

    </body>

    </html>

    but Save button was not perform for save the record.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use debugger to troubleshoot your code and figure out why method is not called.

  • Suggested answer
    Community Member Profile Picture
    on at

    Is he missing save?

    function clickSave(){

    var Xrm = window.parent.Xrm;

    Xrm.Page.data.entity.addOnSave(function (context) {

      alert("Form was saved");

    });

    Xrm.Page.data.save();

    };

  • kiran_rajput Profile Picture
    775 on at

    Not Working

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Then check this article blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools and learn how to troubleshoot your code. Good luck.

  • Verified answer
    kiran_rajput Profile Picture
    775 on at

    Complete

    I use simple code

    function Save()

    {

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

    }

    Thanx..

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans