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, ...
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?

  • Verified answer
    Martin Dráb Profile Picture
    241,511 Most Valuable Professional on at

    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,573 Moderator on at

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

  • OmarAbdlhamed Profile Picture
    48 on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 320 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 210

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans