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 :
Customer experience | Sales, Customer Insights,...
Answered

How to update a field in dynamics 365 form using js code

(0) ShareShare
ReportReport
Posted on by

I have the below js code  i used in the button using ribbon benchwork  and i want  automatically to update the status field to completed if users clicks on that button , but it is not working.

 function (executioncontext) {
"use strict";
var formContext = executioncontext.getFormContext();

if (formContext !== null) {

 formContext.getControl('azmdc_AZstatus').setValue === 100000003;               //   AZstatus is a choice column  and itx value 100000003 = completed



}

}

im not sure if above code correct to update the field, please let me know if need to change anything here. thanks

I have the same question (0)
  • Verified answer
    Flydancer Profile Picture
    1,332 on at

    You need to use formContext.getAttribute('azmdc_AZstatus').setValue(100000003)

  • Community Member Profile Picture
    on at

    The above code works fine if i add on save of the form,,but when I add button using ribbon benchwork it doesn't work

  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    HI,

    If you are adding the button on Form then you need pass execution context as described in below link:

    https://d365demystified.com/2020/09/22/pass-execution-context-to-js-script-function-as-a-parameter-from-a-ribbon-button-in-dynamics-365-ribbon-workbench/

    Once you pass this you will able to get the formcontext and above code will work.

    Thanks,
    Pradeep.

    Please mark this as VERIFIED if it helps.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans