In this post I will going to show you, how to extend the validateField method on a table. As example I used the SalesLine, where I will create a post handler to extend the validateField method.
This kind of extensions were already there to be used in AX 2012, but since we have to work only with extensions now, events got a lot more focus nowadays.
Let’s go: ValidateField Extension
First search the SalesLine table in the AOT, then right click the table and select “Open designer”.
Go to the methods node, to the validateField method, right click, “Copy event handler method” and select “Post-event handler”.
Now create a new class and paste the copied event handler into it
class SaleLine_Events
{
[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 > 10)
{
ret = ret && checkFailed("Line per cent is to high!");
}
break;
}
args.setReturnValue(ret);
}
}
Here I set a few new variables. First of all I called the getThis() method on the passed argsargument.
The actual field to validate is more than interesting for us, for this reason we need to get the passed argument from the original method. In the AOT find the SalesLine again, right click it and select “View code”.
Search for the validateField method and you get the original argument’s name.
public boolean validateField(FieldId _fieldId)
With getArg(“_fieldId”) the original value will be retrieved. To decide if a field is valid or not, the original boolean value has to be known (getReturnValue()) and also a new return value has to be set (setReturnValue(ret)), with our own validation.
Result
In the example above the per cent per line is checked, if it is greater than 10, it will return false and post a message to the infolog.
Here I entered 11.
|
Wednesday, January 30, 2019
D365 Extensions: Extend the validateField Method on a Table
Subscribe to:
Post Comments (Atom)
D365 Extensions: Extend the validateField Method on a Table
In this post I will going to show you, how to extend the validateField method on a table. As example I used the SalesLine, where I will ...
-
In this post I will going to show you, how to extend the validateField method on a table. As example I used the SalesLine, where I will ...
-
Hi All, There is a method named orig() in AX which refers to the last saved state of the current table buffer. The SalesTable form...
-
Hi All, We all know about “View Details” Option in our Ax 2012 Forms and Tables. Here I wrote one sample for how to get that functional...
No comments:
Post a Comment