How to Enable/Disable a Form Button with X++
To enable or disable button in form based on current selected record status through event handlers.
Create a button or choose a button to enable / disable in form.
Go to Form/Datasource/Events/OnActivated, right click and select "Copy event handler for OnActivated method".
Create
new class NNT_WHSWorkTableFormEventHandlers
class
NNT_WHSWorkTableFormEventHandlers
{
[FormDataSourceEventHandler(formDataSourceStr(WHSWorkTableListPage,
WHSWorkTable), FormDataSourceEventType::Activated)]
public static void WHSWorkTable_OnActivated(FormDataSource sender,
FormDataSourceEventArgs e)
{
#define.BTNNAME('YourButtonName')
WHSWorkTable whsWorkTable = sender.cursor();
FormRun element = sender.formRun();
FormControl YourButton = element.design(0).controlName(#BTNNAME);
YourButton.enabled(whsWorkTable.WorkTransType !=
WHSWorkTransType::Sales);
}
}
Build the solution and refresh your browser.
We can
see the button disabled in form.
Comments
Post a Comment