AX Table Methods
1.InitValue();
If we
create a new record from the table browser or from the table method initvalue()
is executed.
It is
used to set a default value for the fields.
Find the
Example One Below
Public void initvalue()
{
Super();
This.customerGroup =”10”;
}
2.ModifiedField();
Each time the Value of a field is changed the method
modified() is called. It is useful to initialize
The values of other field if the value of current
field is changed.
Find the
Example One Below
Public void modified(fieldId _fieldId)
{
Switch (_fieldId)
{
Case fieldnum(MyTestTable, CustGroupId):
This.CurrencyCode=””;
break;
default:
super(_fieldId);
}
}
3.ValidateField():
Method ValidateField() is used for validation only
will return true or false. if the return value is false, the application user will prevented to continue changing a
field value
Find the
Example One Below
Public boolean validateField(fieldId
_fieldToCheck)
{
boolean ret;
ret = super(_fieldIdToCheck);
if(ret)
{
Switch (_fieldToCheck)
{
Case fieldnum(MytestTable,CustName):
If(strlen(this.custname)<=3)
ret=checkfaild(“Customer name must be longer
than 3 characters.”);
}
}
Return ret;
}
After
adding this method ,open table mytestTable using Table browse and press ctrl+N,
in the new record try enter less than 3 characters for field custName, Ax will be
asked to enter value again.
Thus we
validate the data to be entered for a specific field.
4.ValidateWrite():
Method validateWrite() will just check mandatory field
and triggered when the record . checks
Made by validatewrite() are the same as the super()
call in validatefield().so if your conditional is not related to the value an
application user enters in specific field, you should put the validation in validatewrite().
This
method will get to fire when we update a record. here I am using to check
mandatory field for address AccountNum
public boolean validateWrite()
{
boolean ret;
;
if(this.Address != "")
ret = super();
else
warning(" Please fill the address value");
return ret;
}
5.ValidateDelete():
While deleting a record if we
want to put any validation we can use this method. Here once I delete a record
populating a info that deleted record.
public
boolean validateDelete()
{
boolean ret;
ret = super();
info(this.AccountNum);
return ret;
}
ValidateWrite():
This
method will get to fire when we update a record. here I am using to check
mandatory field for address AccountNum
public boolean validateWrite()
{
boolean ret;
;
if(this.Address != "")
ret = super();
else
warning(" Please fill the address value");
return ret;
}
find() :-
All tables should have at least one find method that selects and returns one
record
from the table that matches the unique index specified by the input parameters.
The last input parameter in a find method should be a Boolean variable called
'forupdate' or 'update' that is defaulted to false. When it is set to true, the
caller object
can update the record that is returned by the find method.
See the next example from the InventTable:
static
InventTable find(ItemId itemId, boolean update = false)
{
InventTable inventTable;
;
inventTable.selectForUpdate(update);
if (itemId)
{
select firstonly inventTable
index hint ItemIdx
where inventTable.ItemId == itemId;
}
return inventTable;
}
exists() :-
As with the find method, there should also exist an exists method.
It basically works the same as the find method, except that it just returns
true if a
record with the unique index specified by the input parameter(s) is found.
In the next example from the InventTable you can see that it returns true if
the
input parameter has a value AND the select statement returns a value.
static boolean exist(ItemId itemId)
{
return itemId && (select RecId from inventTable
index hint ItemIdx
where inventTable.ItemId == itemId
).RecId != 0;
}
Display Method:
Indicates
that the methods return value is to be displayed on a forms (or) Reports .The
value cannot be altered in the form or report
Take the
new method in a table, and then drag that method into the grid and
set data source properties. In that field is non-editable.
We can
create display method on the
1. Table
methods
2. Form
methods
3. Form
data source methods
4. Report
methods
5. Report
design methods
Display
Name names ()
{
CustTable custTable;
;
return CustTable::find(this.CustAccount).Name;
}
Edit Method:
Indicates that the methods
return type is to be use to provide information for
a field that is used in a form only
We can create edit method on the
1. Table methods
2. Form methods
3. Form datasoruce methods
Take the new method in the table, and then drag that
method into the grid and set data source properties. In that field is user
can edit it and accept the values to the user and save it CustTable.
Edit Name name(boolean _set ,
Name _name)
{
Name name =
_name;
CustTable custTable;
;
if(_set)
{
if(name)
{
ttsbegin;
custTable =
CustTable::find(this.CustAccount,true);
custTable.Name =
name;
custTable.update();
ttscommit;
}
}
else
{
name =
CustTable::find(this.CustAccount).Name;
}
return
name;
}
No comments:
Post a Comment