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)

Javascript button not triggering

(0) ShareShare
ReportReport
Posted on by 410

Hi ALL,

I craeted a button on the command bar and put a javascript file beneath it, to trigger when the button is clicked. The code is below;

var submitReceipt = function (executionObj) {
			
            var formContext = executionObj.getFormContext();
			formContext.getAttribute("ntt_submittofinance").setValue(1);
			formContext.data.entity.save();
			formContext.data.refresh();
		};


I just want to set a value and then save the record. Nothing works at when the button is clicked. Please someone with experience should. Thanks in advance for the help.

*This post is locked for comments

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

    Hello,

    Try to use following:

    var submitReceipt = function (formContext) {

    formContext.getAttribute("ntt_submittofinance").setValue(1);

    formContext.data.entity.save();

    formContext.data.refresh();

    };

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    I would suggest try to debug your code to make sure you are getting form context. If you are not getting form context you can try to write Xrm.Page.

        var submitReceipt = function () {
            Xrm.Page.getAttribute("ntt_submittofinance").setValue(1);
            Xrm.Page.data.entity.save();
            Xrm.Page.data.refresh();
        };


    You can take help from below reference  getting formcontext from control  -

    http://mscrmtechie.blogspot.com/2018/07/get-formcontext-in-ribbon-command.html

    Hope this helps.

  • Victor Onyebuchi Profile Picture
    410 on at

    This is not working Andrew!!

  • Victor Onyebuchi Profile Picture
    410 on at

     still not working and the link you posted is old, actually foe crm 2013.

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

    Can you please provide screenshot of your button configuration? Like following:

  • Verified answer
    Victor Onyebuchi Profile Picture
    410 on at

    I have got this to work, i repostion the parater on in the ribbon workbench and it worked. Funny how just the position of a parameter can stop javascript from working.

  • Victor Onyebuchi Profile Picture
    410 on at

    Thanbks for your quick response Andrew, I appreciate.

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

    If you got an answer please close thread.

  • Victor Onyebuchi Profile Picture
    410 on at

    Done!!

  • ulli72 Profile Picture
    2 on at
    Hello guys,
    I am facing exactly the same problem, i have placed my button and the java script, but nothing fires. 
    Not even an alert in the first line of the script.
     
    What did help you, finally?  I am not sure what you mean with "reposition the parameters".

    my setup in the ribbon workbench looks like this:
     
     
     
    and this is the script: 
     
    function markAsChargeable(SelectedRecords, formContext)
     alert("Script called");
    for (let i = 0; i < SelectedRecords.length; i++)
    {
        var parameters = {};
        var entity = {};
        entity.id = SelectedRecords[i];
        entity.entityType = "msdyn_invoicelinetransaction";
        parameters.entity = entity;
        // define the data to update a record
        var data = formContext.getAttribute("msdyn_billingtype").setValue(192350001);
        // update the record
        Xrm.WebApi.updateRecord("msdyn_invoicelinetransaction", SelectedRecords[i], data).then(
            function success(result)
            {
                console.log("Success");
                var gridContext = formContext.getControl("Invoice Line Detail Associated View");
                gridContext.refresh();
            },
            function (error)
            {
                console.log(error.message);
            }
        );
    }
     
     
    but.. nothing fires.   Can anybody help? 
     
    thank you,
    Ulli
     

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