Developer

OnValidatedField table event handler method in Dynamics 365 F&O

OnValidatedField table event handler method in Dynamics 365 F&O

Event handlers can be use to fire up your code without the necessary to customize and interfere on core logic and elements.

On the example below i’ll create an event handler that will validate FirstName value of DirPersonName table.

Open DirPersonName table and on tab Events find onValidatedField, copy and Event handler and paste in class you have created before.

Example:

class DirPersonNameTable_EventHandler
{
       /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [DataEventHandler(tableStr(DirPersonName), DataEventType::ValidatedField)]
    public static void DirPersonName_onValidatedField(Common sender, DataEventArgs e)
    {
        DirPersonName dirPersonName = sender as DirPersonName;
        ValidateFieldEventArgs validateFieldEventArgs = e as ValidateFieldEventArgs;
        boolean ret = validateFieldEventArgs.parmValidateResult();
        ;

        if(ret)
        {
            switch(validateFieldEventArgs.parmFieldId())
            {
                case fieldNum(DirPersonName,FirstName):
            if(DirPersonName.FirstName != "MicrosoftDynamics365FO")
                    {
                        ret = checkFailed("Name must be MicrosoftDynamics365FO");
                    }
                    break;

                default:
                    break;
            }
        }
    }

}

Save the class and build the project.

Output:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s