Example for Table Methods in Ax 2012

My Table is:

Bill_TableData

I did Two methods Init value, ValidateField.

CODE:

For Init value Method:  Here iam initializing a default value to all new records which is going to create.

public void initValue()
{
super();
this.Vat=14;
}

For Validate Field Method: Here iam restricting each filed by some condition

public boolean validateField(FieldId _fieldIdToCheck)
{
boolean ret;

ret = super(_fieldIdToCheck);

if(ret)
{
switch(_fieldIdToCheck)
{
case fieldNum(Bill_TabMethod,Quatity):
if(this.Quatity <5)
{
error(“Should give more than FIVE”);
this.Quatity=0;
}
break;
case fieldNum(Bill_TabMethod,Price):
break;
case fieldNum(Bill_TabMethod,Discount):
if(this.Discount>45)
{
this.Discount=0;
error(“Discount Should be Less than 45”);
}
break;
}

}

this.TotalAmt=(this.Quatity * this.Price);//-this.Discount;
this.TotalAmt=this.TotalAmt-this.TotalAmt*(this.Discount/100);

this.NetAmt=this.TotalAmt+this.TotalAmt* (this.Vat/100);

return ret;
}

This is the Output Error while checking the condition on Discount Percentage.

TabMethodError

Advertisements

2 comments on “Example for Table Methods in Ax 2012

  1. Hi, thanks for this post. Couple of questions:
    – What value is assigned to ret after the super call? Seems like it must be TRUE for the IF to work, but why would a failed validation check return TRUE?
    – What effect does the “error” inside the switch have on the caller of validateField which normally issues only a warning and allows the non-validated data to commit to the table?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s