In AX, there can be situations where you have to write code
for table insert and update. Lets say you are exposing some AX logic
by AIF or manipulating data with temp. tables.
In these situations, you may develop only one method both for Insert and
update. All the table fields data can be passed to this method by parameters.
The important question is when to conditionally execute the Insert and Update
method. The answer is the RecID field. RecId is always greater than zero for
any record that is being selected from the database. So for that condition you
can call the update method. Similarly, if the table buffer is populated with
all the fields except the RecID field, then it means that you have just filled all those fields and
Insert methods needs to be called for that condition. To implement this logic
all you have to do is to write the update and insert method in a If condition
like:
If(Table1.Recid > 0 )
{
Table1.update();
}
Else
{
Table1.insert();
}
No comments:
Post a Comment