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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to change or set the value of a field on clicking the save button? How to handle "on Save" event of a record?

(0) ShareShare
ReportReport
Posted on by

I have to change the value of a categorical field from "Draft" to "Approved" of a single record the moment the user clicks on the save button after he's done writing\editing the selected record.

Which event should I use to handle this case?

I think I have to handle this on the datasource level, but there are a lot of apparently similar events I could use, which eventhandler should I choose?

-OnCreated

-OnCreating

-OnValidatedWrite

-OnWritten

I think it must one of these but I can't tell the diffrence,which one is closer to the "On Save" event?

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    OnWritten is when record actually saved. 

    OnValidatedWrite after validation but before save

    OnCreating and OnCreated is about creation but not save.

  • Community Member Profile Picture
    on at

    Thank you very much.

    So which one is triggered by the save action? Should I use the OnWritten?

  • Mea_ Profile Picture
    60,286 on at

    Yes. If you want to do something after record is saved on the form.

  • Suggested answer
    Pedro Tornich Profile Picture
    955 on at

    I think it would be better to use the OnWriting event, then you let the framework write it to the DB, without the need to call the update() method in your code.

    Here is an example:

    [FormDataSourceEventHandler(formDataSourceStr(CustTable, CustTable), FormDataSourceEventType::Writing)]
    public static void CustTable_OnWriting(FormDataSource sender, FormDataSourceEventArgs e)
    {
        CustTable custTable = sender.cursor();
        custTable.Blocked = CustVendorBlocked::All;
    }

    Note: OnWriting would be like placing your code before the super() of the DS write() method, and OnWritten would be like placing it after the super() call.

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at

    It can be done on either event but better to do onValidatedWrite once validations are done you can set field value to approved and it will save it with other changes once record is saved

  • Blue Wang Profile Picture
    Microsoft Employee on at

    Hi Fabio,

    Is it implemented via initValue() on the form?

    Then I think you can modify your field values with the onCreated event handler.

    Here's an example:

    [FormDataSourceEventHandler(formDataSourceStr(EcoResAttribute, EcoResAttribute), FormDataSourceEventType::Created)]
    
    public static void EcoResAttribute_OnCreated(FormDataSource sender, FormDataSourceEventArgs e)
    
    {
    
       FormRun formRun = sender.formRun();
    
       EcoResAttribute ecoResAttribute = sender.cursor();
    
       ;
    
       if (formRun.args().parmEnumType() && formRun.args().parmEnumType() == enumNum(EcoResAttributeModifier)
    
       && formRun.args().parmEnum() == EcoResAttributeModifier::MyDirParty)
    
        {
    
           ecoResAttribute.AttributeModifier = EcoResAttributeModifier::MyDirParty;
    
        }
    
    }

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 771

#2
André Arnaud de Calavon Profile Picture

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

#3
Subra Profile Picture

Subra 496

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans