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

Notifications

Announcements

No record found.

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 501
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
    237,978 Most Valuable Professional on at
    The easiest way is throwing an exception.
     
    Regarding ValidatingWrite, you can cast e to FormDataSourceCancelEventArgs and call cancel(true).
  • CU09091357-0 Profile Picture
    501 on at
     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
    237,978 Most Valuable Professional on at
    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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans