web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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.

(0) ShareShare
ReportReport
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.

I have the same question (0)
  • Suggested answer
    Pankaj Gogoi Profile Picture
    3,177 on at

    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

  • Richa kumari Profile Picture
    25 on at

    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
    3,177 on at

    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

  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    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

  • Richa kumari Profile Picture
    25 on at

    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
    saad nadir Profile Picture
    282 on at

    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

  • Suggested answer
    Pankaj Gogoi Profile Picture
    3,177 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 166

#2
ManoVerse Profile Picture

ManoVerse 54 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans