Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

Posted on by 25

java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

  • Suggested answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi Richa,

    I think you are not passing the PrimaryControl as parameter that's why you you are getting that error. Please follow the steps below and hopefully you are able to resolve the issue.

    Select the CRM Parameter.

    pastedimage1599283739352v1.png

    Select the Primary Control

    pastedimage1599283817059v2.png

    pastedimage1599283849136v3.png

    Here is the JS function for your reference.

    function SetSubmitValue(primaryControl)
    {
        var formContext = primaryControl;
        formContext.getAttribute("new_submit").setValue(true);
    }

    Hope this helps

    Best Regards

    PG

  • Suggested answer
    saad nadir Profile Picture
    saad nadir 282 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    the correct thing to do is the following :

    First your javascript method should have the argument formContext rather than executionContext for ribbon workbench.

    The code will be the following :

    function OnSubmit(formContext)
    {
        formContext.getAttribute("atci_submit").setValue(0);
    }

    The second thing to do in your ribbon workbench, go to the command of your button and add the primaryControl as a parameter to your javascript method.


    pastedimage1599254521853v2.png
     

    This should resolve your problem. Good luck

  • Richa kumari Profile Picture
    Richa kumari 25 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi Pankaj,

    Thanku for your reply.

    yes, i am getting the error like  " Cannot read property 'getFormContext' of undefined"

    so the ask from me is the below one:

    Add a custom ribbon button called "Submit" and place it on Travel Plane form after new button.(done)

    On Click of the button, the submit field on the form should set to yes.

    Add a Jscipt called atci_/Scripts/TravelPlan.OnLoad.js.  Write a script to set the Submit field to Yes.

    Call that Script on click of submit button.

    assignment.PNG

    Regards,

    Richa

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi,

    If you are calling this function on click on ribbon button then you will not get executionContext automatically.

    Check below article on how to get formContext from ribbon workbench.

    blog.magnetismsolutions.com/.../getting-dynamics-365-formcontext-from-ribbon-workbench

    Please mark my answer verified if i were helpful

  • Suggested answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi Richa,

    you should change the setValue(0) to setValue(false);

    it will not return anything so your const value will be undefined. How are you calling this function and what are you trying to return?

    You also need to pass the executionContext. In case of Ribbon button you need to pass the CRM Parameter of Primary Control.

    pastedimage1599130004426v1.png

    Best Regards

    PG

  • Richa kumari Profile Picture
    Richa kumari 25 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi Pankaj,

    i am using the below piece of code, but it is getting error out.

    as i am new to javascript so not sure where i am wrong.

    function OnSubmit(executionContext)

    {

    var formContext=executionContext.getFormContext() ;

            const value = formContext.getAttribute("atci_submit").setValue(0);

            return value===true;

    }

    Regards,

    Richa

  • Suggested answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.

    Hi,

    You can use the value or label.

    Xrm.Page.getAttribute("field").setValue(0);
    or
    formContext.getAttribute("field").setValue(0);
    
    Xrm.Page.getAttribute("field").setValue(true);

    Hope this helps

    Best Regards

    PG

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans