Example: You have a Table : VendTable. Now you want to write some code that needs to be executed before insert method. How to do that and how to get the record in that method.
- Create an Extension Class for VendTable. Ex: ABVendTable_Extension
- Now Goto AOT > DataModel>Tables>VendTable. Right Click on table and click Open
- Now Expand Methods on Table > Right Click on Insert > Click Copy Event Handler Method > Click Pre-Event Handler.
- Now Paste this into the Extension class that we created in Step 1.
- So Inside code of that method, if you want to get the record the code will be like this as shown below.
- The if loop in below record is something i have written as i have created two fields and if i enter 30 in VendorRank, it should change value on other string field to Thirty. This is just an example i took to use pre insert method.
[ExtensionOf(tablestr(VendTable))]
Public static class ABVendTable_Extension
{
/// <summary>
///
/// </summary>
/// <param name="args"></param>
[PreHandlerFor(tableStr(VendTable), tableMethodStr(VendTable, insert))]
public static void VendTable_Pre_insert(XppPrePostArgs args)
{
VendTable VendTable = args.getThis(); //Code to get record.
if(VendTable.VendorRank == 30)
{
VendTable.VendorRankName = "Thirty";
}
// args.setReturnValue(VendTable);
}
}
Leave a comment