Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript button not triggering

Posted on by 390

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

  • ulli72 Profile Picture
    ulli72 2 on at
    Javascript button not triggering
    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
     
  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: Javascript button not triggering

    Done!!

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Javascript button not triggering

    If you got an answer please close thread.

  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: Javascript button not triggering

    Thanbks for your quick response Andrew, I appreciate.

  • Verified answer
    Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: Javascript button not triggering

    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.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Javascript button not triggering

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

  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: Javascript button not triggering

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

  • Victor Onyebuchi Profile Picture
    Victor Onyebuchi 390 on at
    RE: Javascript button not triggering

    This is not working Andrew!!

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Javascript button not triggering

    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.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Javascript button not triggering

    Hello,

    Try to use following:

    var submitReceipt = function (formContext) {

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

    formContext.data.entity.save();

    formContext.data.refresh();

    };

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans