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

Form DataSource Deleting EventHandler

(0) ShareShare
ReportReport
Posted on by 48

i wanna prevent the user from delete a record based on condition

i used eventhandler for form datasource deleting eventhandler i used the below code

[FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::Deleting)]
public static void PurchTable_OnDeleting(FormDataSource sender, FormDataSourceEventArgs e)
{
// ValidateEventArgs args = e as ValidateEventArgs;
//boolean result = args.parmValidateResult();

PurchTable purchTable = sender.cursor() ;

if(purchTable.purchid == '1234')
checkFailed("you can not delete this PO");


}
but still can deleted it
i tried to get the eventargs result by below code

// ValidateEventArgs args = e as ValidateEventArgs;
//boolean result = args.parmValidateResult();

but it gives and error i wanted to do like that

// ValidateEventArgs args = e as ValidateEventArgs;
//boolean result = args.parmValidateResult()

if(purchTable.purchid == '1234')
result = result  && checkFailed("you can not delete this PO");

but it gives an error

any help please?

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at
    RE: Form DataSource Deleting EventHandler

    You claimed your question was about AX 2012, but I'm pretty sure it's wrong and it's actually about F&O. Therefore I've moved the thread to an F&O forum and deleted "AX 2012" tag. Let me know if I made a mistake.

    The problem with your code is that it never sets the validation result to false. It only adds a warning message to infolog, but the validation still succeeds.

    You need to use args.parmValidateResult(false) or args.parmValidateResult(checkFailed(...)).

    Also, if you need a help with an error, you should tell us what error you get and where. "It gives an error" isn't enough. Please realize that we can't help you if you don't give us enough informatiom about your problem.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Form DataSource Deleting EventHandler

    Hi Omar, Instead of writing this validation on OnDeleting event, please use OnValidatingDelete event of form datasource.

  • OmarAbdlhamed Profile Picture
    48 on at
    RE: Form DataSource Deleting EventHandler

    Hi Martin , Hi Mohit

    thanks for your feedbacks

    my requirement is prevent the user of deleting purchase order record based on certain condition in PurchTable form

    my question was how to prevent it , if i write checkfailed the deleting still occur

    but now i found my solution there is the below code

    [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::ValidatingDelete)]

       public static void PurchTable_OnValidatingDelete(FormDataSource sender, FormDataSourceEventArgs e)

       {

           FormRun                 form           = sender.formRun();

           FormDataSource purchTable_ds   =          form.dataSource(formDataSourceStr(PurchTable, PurchTable)) as

              FormDataSource;

           PurchTable      purchTable = purchTable_ds.cursor();

           var args = e as FormDataSourceCancelEventArgs;

           if(purchTable.purchid == '123')

           {

               boolean doCancel = !checkFailed("you can not delete this PO");

               args.cancel(doCancel);

           }

       }

    my solution was in the below 3 lines

    var args = e as FormDataSourceCancelEventArgs;

     boolean doCancel = !checkFailed("you can not delete this PO);

           args.cancel(doCancel);

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
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans