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

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Automatically save table form when field value changes - JavaScript

(0) ShareShare
ReportReport
Posted on by 50

Hi,

I have created a simple logic which triggers an alert box when a specific field value changes on my form. 

It is a confirmation alert box where you have to "verify" before the field value changes from No to Yes. 

I would like to extend this logic to include an automatic save of the table form itself. Once you have clicked "confirm" on the alert box and the field value changes, then it should trigger an automatic save of the form. 

Below is the logic I have so far: 

function test_markcompleteuser_onchange ()
{
var approval = confirm("Do you wish to send this record for approval?");
if (approval)
{
alert("Press OK and save the form to proceed");
}
else
{

}
}

Any help would be greatly appreciated. Thanks!

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Automatically save table form when field value changes - JavaScript

    Hi Joakim Gunstad,

    You can use formContext.data.save() method to automatic  save your record in your logic.(Doc:docs.microsoft.com/.../save)

    Below is my test code:

    function onChange(executionContext){
    var formContext = executionContext.getFormContext();
    var approval = confirm("Do you wish to send this record for approval?");
    if (approval)
    {
    console.log("Press OK and save the form to proceed");
    formContext.data.save().then(
    function success(){
    console.log("data is saved");
    },
    function fail(error){
    Xrm.Navigation.openAlertDialog({
    text: error.message
    });
    }
    );
    }
    else
    {
    console.log("Press cancel");
    }
    }

    Result:

    pastedimage1639103930165v1.gif

    Note:

    When you create on change event, please check the below setting:

    pastedimage1639103987497v2.png

  • Joakim Gunstad Profile Picture
    50 on at
    RE: Automatically save table form when field value changes - JavaScript

    Hi . Thanks for your response and solution. It works perfectly!

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Sahan Hasitha Profile Picture

Sahan Hasitha 271

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 91 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 76 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans