Skip to main content

Notifications

Microsoft Dynamics CRM forum
Answered

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

Posted on by Microsoft Employee

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

  • Verified answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: How to update a field in dynamics 365 form using js code

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to update a field in dynamics 365 form using js code

    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
    Flydancer Profile Picture
    Flydancer 1,332 on at
    RE: How to update a field in dynamics 365 form using js code

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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans