In this blog, I will try to explain how to write code for validate write for a table-level event handler using X++ in D365FnO.
To begin, create a new class and name it “VendGroup_Table_EventHandler”. Then, copy the code provided below into the newly created class.
class VendGroup_Table_EventHandler
{
[DataEventHandler(tableStr(VendGroup), DataEventType::ValidatedWrite)]
public static void VendGroup_onValidatedWrite(Common sender, DataEventArgs e)
{
VendGroup vendGroup = sender as VendGroup;
ValidateEventArgs validateEventArgs = e as ValidateEventArgs;
boolean ret = validateEventArgs.parmValidateResult();
if(ret)
{
if(vendGroup.GroupRegion == "")
{
ret = checkFailed("Vendor region must be filled.");
validateEventArgs.parmValidateResult(ret);
}
}
}
}
See the following error screenshot: