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)

Calling a Button click from the Entity Form on its attribute value Change or through any another JS

(0) ShareShare
ReportReport
Posted on by 745

Call a function in Html webresource on a form attribute value change 

this is how i did 

Create a JS webresource for adding onchange event on that field

function addmyonchange (){

if (Xrm.Page.getAttribute("Your_Field") != null) {
Xrm.Page.getAttribute("Your_Field").addOnChange(mysearchbutton );
}

function to call the button click function 

function mysearchbutton (){

var obj = Xrm.Page.getControl("WebResource_<name>").getObject();
obj.contentWindow.document.getElementById('<button_ID>').click()

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello Moin,

    Are you getting any error in your code?

    I would suggest go to F12 window of the browser and find the button I'd using selector of F12 window and then directly write like below.

    document.getElementById('<button_ID>').click();

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    You can also try to call a html page method and from there you can call button on click event. But yes debugging can give your more option here to check if you are getting object correctly or not.

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Hi Moin,

    Are you getting any errors, or just asking for suggestions?

    What I would recommend is create a function on your html web resource to handle the calling of the button, and then from your mysearchbutton, call that function directly.

    Xrm.Page.getControl("WebResource_<Name>").getObject().contentWindow.window.myFunction();

    Hope this helps.

  • Verified answer
    MMK Profile Picture
    745 on at

    Hi All,

    Thanks for your help

    That JS  and HTML are two different web resources and JS was actually loading before the HTML iframe is loaded so the JS was unable to find the html element

    So i used set timeout of  1 second and that run successfully

    function mysearchbutton () {

    setTimeout(function () {
    debugger;
    var obj = Xrm.Page.getControl("WebResource_<name>").getObject();
    obj.contentWindow.document.getElementById('<button_ID>').click()
    }, 1000);

    }

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