Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Automatically save table form when field value changes - JavaScript

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!

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

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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

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,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans