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

enabling /disabling buttons on form

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

I have a form namely salestable  in which i have a custom button .

Created event handler class & added  onActivated event for salestable datasource of this form (1st code box)

The logic works fine to enable/disable button, only 1 issue that when you create a new SO and add salesline the button does not enable itself until & unless you refresh the form.

Any idea what could be done in x to fix this issue, i.e. the button is enabled as soon as new salesline item is added .

Do i need to write code for event onValidateWrite at salesine datasource for salestableform  , if yes what should i write.

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated), 
        SuppressBPWarning('BPParameterNotUsed', 'Parameter e not used')]
    public static void salesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormControl     myFormControl    = sender.formRun().design().controlName(formControlStr(SalesTable, MyCustomButton));
        SalesTable      salesTable                = sender.cursor();
       

        if(SalesLine::exist(salesTable.salesid) && salesTable.SalesStatus == SalesStatus::Backorder) 
        {
            myFormControl.enabled(true);
        }
        else
        {
            myFormControl.enabled(false);
        }
  
    }

Thanks

Mav

Thanks

Mav

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,953 Most Valuable Professional on at

    You should do it when a line is created, i.e. in write() (or a corresponding event).

    validateWrite() isn't the right place, because it might be called multiple times before a line is actually saved (or maybe it will never be saved).

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Your condition enables the button only if there is at least one SalesLine in the database, and SalesStatus is BackOrder.

    So, it will only be enabled once the line has been saved and form is refreshed.

    You can add similar code to the write() method / event of the SalesLine data source. Don't put your code to validateWrite method if it has nothing to do with validating the record.

  • Mav Profile Picture
    on at

    Ok so no validatewrite event handler, i got that. Now i only have the above code in activate event & issue is the user does not want to refresh the form to see if button is enabled , can you please share where & how to refresh the form within the code.

    Thanks

    Mav

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Please read my previous reply again, it contains information that will help you forward.

  • Mav Profile Picture
    on at

    Sorry about this, yes it works after adding similar active handler code to write method.

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 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans