There are times when a developer wants to manipulate properties of fields on a form using X++; specifically properties such enabling or disabling visibility, editing, view, mandatory settings etc. In my opinion you should do this if possible on the form data source using the data source function to control field and datasource controls
Below are examples of how to acheive this. I place a lot of my toggling code on buttons and the active method(s) of forms. In standard AX there are many examples of how to achieve this functionality so I will show standard and some of my own.
Standard – Standard using boolean method from the salesTableType class to determine visiblity
salesTable_ds.object(fieldnum(SalesTable, CustAccount) ).allowEdit(editSalesTableType.editCustAccount());salesTable_ds.object(fieldnum(SalesTable, InvoiceAccount)).allowEdit(editSalesTableType.editInvoiceAccount());
salesTable_ds.object(fieldnum(SalesTable, vatNum) ).allowEdit(editSalesTableType.editVATNum());
salesTable_ds.object(fieldnum(SalesTable, InclTax) ).allowEdit(editSalesTableType.editInclTax());
My examples – I am basing access to buttons and fields on whether a sales order is invoiced and if the invoice has been paid for
select firstonly custInvoiceJour where custInvoiceJour.SalesId == salesTable.SalesId; custTrans = custTrans::findFromInvoice(custInvoiceJour.InvoiceId);
if(salesTable.SalesStatus == salesStatus::Invoiced) { CustInvoiceJournal.enabled(true); if(custTrans.open() == true) { wfsWalkupPayment.enabled(true); } else { wfsWalkupPayment.enabled(false); } wfsCSDeliveryNote.enabled(true); SalesTable_ds.object(fieldnum(SalesTable,DeliveryAddress)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,DeliveryName)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,DeliveryStreet)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,DeliveryCity)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,CustAccount)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,wfsCSPhone)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,Email)).allowEdit(false); SalesTable_ds.object(fieldnum(SalesTable,CustomerRef)).allowEdit(false); } else { CustInvoiceJournal.enabled(false); wfsCSDeliveryNote.enabled(false); wfsWalkupPayment.enabled(true); SalesTable_ds.object(fieldnum(SalesTable,DeliveryAddress)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,DeliveryName)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,DeliveryStreet)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,DeliveryCity)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,CustAccount)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,Email)).allowEdit(true); SalesTable_ds.object(fieldnum(SalesTable,CustomerRef)).allowEdit(true); }
No comments:
Post a Comment