In Dynamics Ax 2009, we want a field that will be calculated based off another field in the same table.
Although it might be nice to use a display method or something, we have to actually store the value (management is sc开发者_Go百科ared of dynamic calculations because the previous product used them and was slow (like anything in AX is fast!)).
To put the icing on the cake, they want it to work two-way:
If we have FieldA, calculate and store FieldB. If we have FieldB, calculate and store FieldA. If we have both or none, do nothing.
Is there anything built into Dynamics AX that can help me?
First, override table's method insert()
, e.g.:
public void insert()
{
;
this.FieldB = this.FieldA * 2;
super();
}
Then override update()
, e.g.:
public void update()
{
if (this.FieldA == this.orig().FieldA && this.FieldB != this.orig().FieldB)
{
this.FieldA = this.FieldB / 2;
}
else
{
this.FieldB = this.FieldA * 2;
}
super();
}
These are only examples, use your own judgement how the methods should be overridden. Lastly, override modifiedField()
, which will be used only when the fields are modified manually in forms:
public void modifiedField(fieldId _fieldId)
{
;
super(_fieldId);
switch (_fieldId)
{
case fieldnum(MyTable, FieldA) :
this.FieldB = this.FieldA * 2;
break;
case fieldnum(MyTable, FieldB) :
this.FieldA = this.FieldB / 2;
break;
}
if (this.isFormDataSource())
this.dataSource().refresh();
}
P.S. Keep in mind that insert()
and update()
are not called when you are using doinsert()
, doupdate()
, or skipDataMethods()
.
See another related answer here: Automatic field values changed according to master table field modified In Axapta
精彩评论