Example for Table Methods in Ax 2012
My Table is:
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;
}
{
super();
this.Vat=14;
}
For Validate Field Method: Here iam restricting each filed by some condition
public boolean validateField(FieldId _fieldIdToCheck)
{
boolean ret;
{
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;
}
{
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.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.
No comments:
Post a Comment