Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

validate delete code

(0) ShareShare
ReportReport
Posted on by 129
I have extended a form to write validation on timesheet delete line in the below event handler:
what should i write to prevent delete if enum value is yes.
 
 [FormControlEventHandler(formControlStr(TSTimesheetEntry, DeleteLine), FormControlEventType::Clicked)]
    public static void DeleteLine_OnClicked(FormControl sender, FormControlEventArgs e)
    {
         FormDataSource    Table_ds   =  sender.formRun().dataSource(formDataSourceStr(form, Table));
        Table record = Table_ds.cursor() as Table;
        if (record.field == NoYes::Yes)
        {
               
            checkFailed(/PTO line updation is not allowed/);
           
               
        }
 

       
    }
pls suggest.
        
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    validate delete code
    Clicked is a wrong event for validation, it's too late there and pressing a button isn't the only way how to delete a record.
     
    Instead, override validateDelete() method of the table or handle its ValidatingDelete event.
  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    validate delete code
    Hi Ayushii,
     
    I think adding clicked eventHandler for the DeleteLine button won't work here. 
    It's better to add the validation at table level of TsTimesheetLine.
    Add your logic on the ValidateDelete method on the table. You can use COC or event handlers.
     
    Thanks,
    Girish S.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans