Raju's Dynamics AX / Dynamics 365 Finance and Operations Blog

BLOG BY RAJU. DYNAMICS AX , DYNAMICS 365 FINANCE AND OPERATIONS EXPLORER

Form Datasoure field OnValidating Event how to get the record inside code in D365FO; Dynamics 365 Finance and Operations

I created a extension table for VendTable. Then Added two fields. One is VendorRank. and I added these two fields on VendTable Form extension form. In this post, i will show how to get the current record inside datasource field OnValidating event method.

  1. Create an Extension Class for VendTable form. Ex: ABVendTableForm_Extension.
  2. Now Expand VendTable.Extension form that is created and where you added the two fields.
  3. Now Expand the Datasource VendTable on form > Expand Fields > Expand Field VendorRank > Expand Events > Right Click on “Onvalidating” > Click “Copy Event handler Method”
  4. Now Paste that inside the class you created in step 1.
  5. Code looks like this

class ABVendTableForm_Extension
{

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataFieldEventHandler(formDataFieldStr(VendTable, VendTable, VendorRank), FormDataFieldEventType::Validating)]
public static void VendorRank_OnValidating(FormDataObject sender, FormDataFieldEventArgs e)
{
    boolean ret;
    FormDataSource VendTable_ds = sender.datasource(); // Code to get Datasource

    VendTable VendT = VendTable_ds.cursor(); //Code to get Current Record
    ret = true;

    if(VendT.VendorRank == 50)
    {
        ret = checkFailed("Rank 50 is not possible"); //I am just throwing an error if entered value on Vendor Rank is 50

    }

    sender.setValue(ret); //returning the error. 

}

}

Published by

Leave a comment

Design a site like this with WordPress.com
Get started