Sunday, February 5, 2012

Edit Methods versus Display Methods

Display Methods:

In some scenarios, we need to display some values derived from other columns and those are not associated directly with the database, like Amount fields (Unit*Price). In that case there are display methods that perform that functionality.
 display Amount amount()
{
    AmountMST  amount; 

    amount = this.unitprice * this.quantity; 

    return amount;
} 

Edit Methods:
In AX 2009, when reference controls were not available, in table if there is a relation created on the basis of recId i.e. there is a child table and it contains the record Id of the parent Table. When that child table binds to form, (to display and select the user friendly information from the parent table, lookup controls were used). The record Id of the user friendly value is saved on the table with the help of the edit methods.
To give an example of an edit method, we will create a new field in the CarTable to hold the mileage of the car and have an edit method in RentalTable that enables the users to be in the RentalTable form and still edit the field in CarTable.

We'll create an extended data type of type integer for the new field and call it Mileage. Then we'll dd the field to the CarTable.

The edit method in RentalTable will then look like this: 

//This material is copyright and is licensed for the sole use by ALESSANDRO CAROLLO on 18th December, Chapter 4 [ 105 ]

edit Mileage mileage(boolean _set, Mileage value)
{
    CarTable carTable;
    Mileage  ret;

    // find the car records from the car table with update = true
    carTable = CarTable::find(this.CarId, _set);

    if (_set)
    {
        ttsbegin; 

        carTable.Mileage = value;
        carTable.update();

        ttscommit;
    }
    else
    {
        ret = carTable.Mileage;
    }

    return ret;
} 



No comments:

Post a Comment