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 :
Finance | Project Operations, Human Resources, ...
Answered

Cancel Inserting, Updating and ValidateWrite events handlers

(2) ShareShare
ReportReport
Posted on by 480
I created a class that holds some event handlers, I added my own condition, and my code is entering my condition.
And based on my condition I want to cancel the inserting, updating, and validateWrite to return false but in event handlers, how?
 
[FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTransDaily, LedgerJournalTrans), FormDataSourceEventType::ValidatingWrite)]
public static void LedgerJournalTrans_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)
{
    if(some codition)
    {
        return false and don't insert or update the record
    }
}

--------------------------------------------------------------------------

[DataEventHandler(tableStr(LedgerJournalTrans), DataEventType::Updating)]
public static void LedgerJournalTrans_onUpdating(Common sender, DataEventArgs e)
{

    if(some codition)
    {
        don't update the record
    }
}
--------------------------------------------------------------------------

[DataEventHandler(tableStr(LedgerJournalTrans), DataEventType::Inserting)]
public static void LedgerJournalTrans_onUpdating(Common sender, DataEventArgs e)
{

    if(some codition)
    {
        don't insert the record
    }
}
 
Categories:
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    Cancel Inserting, Updating and ValidateWrite events handlers in D365FO X++
    The easiest way is throwing an exception.
     
    Regarding ValidatingWrite, you can cast e to FormDataSourceCancelEventArgs and call cancel(true).
  • CU09091357-0 Profile Picture
    480 on at
    Cancel Inserting, Updating and ValidateWrite events handlers in D365FO X++
     thank you for your response, but in case of inserting and updating, which are on a table level, how can I cast the dataEvenArgs e, in a way that I can cancel the operation?
  • Verified answer
    Martin Dráb Profile Picture
    236,297 Most Valuable Professional on at
    Cancel Inserting, Updating and ValidateWrite events handlers in D365FO X++
    Throw an exception to prevent the record from being inserted or updated.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans