Edit method

Introduction
An edit method is not a physical field in a table but rather a method of entering and displaying information from another table or source. Like a display method it appears like a "normal" field and it can be used in forms and reports. For more information about display methods go to MSDN.

Usage
An edit method can be created on either a table (in which case it is available for all forms using that table), or on the datasource of a specific form (in which case it is available only on that form).

Edit methods must be created using a specific signature, which varies depending on the location of the method.

Edit methods on tables
When declared on a table, edit methods must be preceded with the keyword edit and expect exactly two parameters. The following example is a standard edit method from the SalesTable table.

Parameter _set indicates whether the edit method is being used to show (_set = false) or modify (_set = true) data. This is set automatically by the caller form.

Parameter _exchRate in the example below should be declared using the same type as the method return value, and contains the new value to be set when _set is true. Then _set is false then that value should be ignored by the method programmer.

Irrespective of the value of _set, the method must always return the current calculated value.

public edit SalesFixedExchRate editFixedExchRate(boolean _set, SalesFixedExchRate _exchRate) {   ExchangeRateHelper exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(curext).RecId), this.CurrencyCode);

if (_set) {       this.FixedExchRate = exchangeRateHelper.prepareExchangeRateForStorage(_exchRate); }   else {       _exchRate = exchangeRateHelper.displayStoredExchangeRate(this.FixedExchRate); }

return _exchRate; }

Edit methods on datasources
On a form datasource, an additional parameter is required indicating against which record the method should operate. In the following example from standard Ax 2012 it is the _purchParmTable parameter. The order of the parameters is significant and must be followed exactly.

//BP Deviation documented edit boolean paymentIdValidated(boolean             set,                                 PurchParmTable     _purchParmTable,                                 NoYes              _validated) {   NoYes  validated;

if (_purchParmTable.RecId) {       if (!paymentIdValidatedSet) paymentIdValidatedSet = new Set(typeName2Type(extendedtypestr(recId)));

if (set) {           validated = _validated; if (_validated) paymentIdValidatedSet.add(_purchParmTable.RecId); else paymentIdValidatedSet.remove(_purchParmTable.RecId); }       else {           validated = paymentIdValidatedSet.in(_purchParmTable.RecId); }   }    else {       validated = NoYes::No; }

return validated; }

Caching
Since Ax 2009, edit methods can also be cached on forms. See the caching section of display methods for further details.