Retrieving Records Passed to Forms as Parameters

Override the form’s init method to reference the passed record. In the example below the salesTable variable is declared in the form’s class declaration, making it global to the form.


public void init()
{
    ;

    super();

    if (element.args().record() && element.args().record().TableId == TableNum(SalesTable))
    {
        salesTable = element.args().record();
    }
}

It is easiest to pass the parameter using a menu item with it’s ‘parameter’ property set to the appropriate type, and then making reference to the datasource for the type you wish to pass in the calling form’s menu item properties.

If however there is a need to set the parameter record in X++, something like this would work:


    Args        args;
    SalesTable  salesTable;
    ;
  
    args = new Args();
    salesTable = salesTable::find("blah");
    
    if (salesTable.RecId)
    {
        args.record(salesTable);
    }