The following class is the extension of the ProdParmStartUp form in D365 F&O, where I will disable a field in the grid, based on a condition. Therefore users won’t be able to edit that field when that condition is met.
*ProdParmStartUp: This form opens up on the Production order page when we click on the start button
[ExtensionOf(formStr(ProdParmStartUp))]
final class MZNNM_ProdParmStartUp_Extension
{
[FormDataSourceEventHandler(formDataSourceStr(ProdParmStartUp,ProdParmStartUp), FormDataSourceEventType::Activated)]
public static void FormDatasource_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
FormDataSource fds = sender.formRun().dataSource(formDataSourceStr(ProdParmStartUp,ProdParmStartUp));
ProdParmStartUp dsTable = fds.cursor();
FormRun fr = sender.formRun();
ProdTable prodTable;
boolean allowQtyEdit;
prodTable.clear();
select * from prodTable
where prodTable.ReqPOId != ”
&& prodTable.ProdId == dsTable.ProdId;
allowQtyEdit = true;
if(prodTable){
allowQtyEdit = false;
}
fds.object(fieldNum(ProdParmStartUp,StartUpQty)).allowEdit(allowQtyEdit);
fds.object(fieldNum(ProdParmStartUp,StartUpQty)).enabled(allowQtyEdit);
//fds.refresh();
fds.reread();
}
}