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

Announcements

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

    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

    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

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
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 68 Super User 2026 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 53 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 47 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans