VALIDATE FIELD CODE IN D365
For eg. if you write the discount value as 101 you get the error.This error is getting called from the validate field.
public boolean validateField(FieldId _fieldIdToCheck)
{
boolean ret;
ret = super(_fieldIdToCheck);
if(ret)
{
switch(_fieldIdToCheck)
{
case fieldNum(TableName,Quantity):
if(this.Quantity>100)
{
error("Quantity should be less than 100);
}
break;
//you can add as many conditions as per the number of fields.
//same condition can be shared by two fields ..see below eg.
case fieldNum(TableName,Price):
case fieldNum(TableName,PriceMST):
if(this.PurchQty == 0)
{
error("Quantity cannot be zero");
}
}
similarly the event handler for the D365 is written as follow.
Post -> it gets called after the standard validatefield.
[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, validateField))]
public static void SalesLine_Post_validateField(XppPrePostArgs args)
{
SalesLine salesLine = args.getThis();
FieldId fieldId = args.getArg("_fieldId");
boolean ret = args.getReturnValue();
switch(fieldId)
{
case fieldNum(SalesLine, LinePercent):
if (salesLine.LinePercent > 100)
{
ret = ret && checkFailed("Line per cent is Invalid");
}
break;
}
args.setReturnValue(ret);
}
Thanks,
Vikas Mehta.
Yes! Finally someone writes about %keyword1%.
ReplyDeleteP0wer bi training
P0wer bi online course