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

Dialog Override Modified mehtod in Ax 2012

class Test_DialogField extends RunBasebatch
{
CustAccount CustId;
DialogField dialogCustId;
DialogField dialoglName;
Dialog dialog;

#define.CurrentVersion(1)

#localmacro.CurrentList
CustId
#endmacro
}

public container pack()
{
return connull();
}

public boolean unpack(container packedClass)
{
return true;
}

static void main(Args args)
{
Test_DialogField tmpDialogField = new Test_DialogField();
;

if (tmpDialogField.prompt())
tmpDialogField.run();
}

public void dialogPostRun(DialogRunbase tmpdialog)
{
super(tmpdialog);
tmpdialog.dialogForm().formRun().controlMethodOverload(true);
tmpdialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

protected Object dialog()//DialogRunbase tmpdialog, boolean forceOnClient)
{
;
dialog = super();//tmpdialog,forceOnClient);
dialogCustId = dialog.addFieldValue(typeid(CustAccount),”Customer”, “Customer”);
dialoglName = dialog.addFieldValue(typeid(Name),”Name”, “Name”);

return dialog;
}

public boolean fld1_1_modified()
{
FormStringControl control = dialog.formRun().controlCallingMethod();
boolean isFieldModified;
;
isFieldModified = control.modified();

if(isFieldModified)
{
dialoglName.value(custTable::find(control.text()).Name);
}
return isFieldModified;
}