Monday, February 17, 2014

Dependent lookup in dialog class

class dialogDepLookup extends runbase
{
    DialogRunbase       dlg;
    DialogField     fieldCustAccount;
    DialogField     fieldCustTransDate;

    CustAccount     custAccount;
    TransDate       transDate;

    #define.CurrentVersion(1)

    #localmacro.CurrentList
        custAccount,transDate

    #endmacro
}
protected Object dialog()
{
    dlg = new DialogRunbase("test",this);


    //dlg                 = super();
    fieldCustAccount = dlg.addFieldValue(typeId(CustAccount),'', "Customer Account");
    fieldCustTransDate = dlg.addFieldValue(typeId(TransDate), datenull(), "Transaction Date");

    return dlg;
}
public void dialogPostRun(DialogRunbase _dialog)
{
    super(_dialog);

    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
void Fld2_1_lookup()
{
    Object control = dlg.formRun().controlCallingMethod();
    ;

    this.transDate_Lookup(control, fieldCustAccount.value());
}
public boolean getFromDialog()
{
    boolean ret;
    ;

    ret             = super();
    custAccount  = fieldCustAccount.value();
    transDate         = fieldCustTransDate.value();

    return ret;
}
public container pack()
{
    return [#CurrentVersion, #CurrentList];
}
void run()
{
    //#OCCRetryCount
    //setprefix("@SYS3761");

    try
    {
        info(custAccount);
        info(date2strxpp(transDate));
    }
    catch (Exception::Deadlock)
    {
        retry;
    }   
}
public void transDate_Lookup(FormStringControl _ctrl,CustAccount _custAccount)
{
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(CustTrans),_ctrl);
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource = query.addDataSource(tablenum(CustTrans));
    ;

    sysTableLookup.addLookupfield(fieldnum(CustTrans,TransDate));
    queryBuildDataSource.addRange(fieldnum(CustTrans,AccountNum)).value(_custAccount);
    queryBuildDataSource.orderMode(orderMode::GroupBy);
    queryBuildDataSource.addSortField(fieldnum(CustTrans,TransDate));

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public boolean unpack(container _packedClass)
{
    Integer version = RunBase::getVersion(_packedClass);
    ;

    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] = _packedClass;
            break;

        default:
            return false;
    }

    return true;
}
public static void main(Args    _args)
{
    dialogDepLookup dialogDepLookup = new dialogDepLookup();
    ;
    if (dialogDepLookup.prompt())
    {
        dialogDepLookup.run();
    }
}

2 comments:

  1. In your example, where call Fld2_1_lookup?

    ReplyDelete
    Replies
    1. Thank you for viewing this post. When the Fld2's lookup (drop-down) is clicked, this method is called by the system automatically.

      Delete