Oct 30, 2012

How to get caller form name ?


This is an example for enabling and disabling of button1 and button2  on basis of caller form

Public void buttonEnable()
{
    UserGroupList           userGroupList,userGroupList1;
    ProjParameters          projParameters;
    formRun                    caller;
    ;
    caller = element.args().caller(); // caller form

    if(caller.args().name() == formStr(ProjTable)) // caller form name
    {
        projParameters = ProjParameters::find();
        
       // Checking that the CurUserId() is there of one particular group or not

        Select userGroupList where userGroupList.UserId == curUserId()
                                   && userGroupList.groupId == projParameters.SalesAcceptanceChangeOrder;
        if(userGroupList)
        {
            Button1.enabled(true);
        }
        else
        {
            Button1.enabled(false);
        }
        Select userGroupList1 where userGroupList1.UserId == curUserId()
                                   && userGroupList1.groupId == projParameters.CommercialAcceptanceChangeOrder;
        if(userGroupList1)
        {
            Button2.enabled(true);
        }
        else
        {
            Button2.enabled(false);
        }
    }
    if(caller.args().name() == formStr(ProjQuoteTable))
    {
        projParameters = ProjParameters::find();

        Select userGroupList where userGroupList.UserId == curUserId()
                                   && userGroupList.groupId == projParameters.SalesAcceptanceQtn;
        if(userGroupList)
        {
            Button1.enabled(true);
        }
        else
        {
            Button1.enabled(false);
        }
        Select userGroupList1 where userGroupList1.UserId == curUserId()
                                   && userGroupList1.groupId == projParameters.CommercialAcceptanceQtn;
        if(userGroupList1)
        {
            Button2.enabled(true);
        }
        else
        {
            Button2.enabled(false);
        }
    }

}

Oct 23, 2012

How to filter the records in dialog field values ?


The following example class is to filter the records in a dialog fields

class TestDialogFields
{
    Dialog                       dialog;   
    DialogField              emplIdField;
}

Dialog showDialog()
{
    FormRun        formRun;
    ;
    dialog         = new Dialog('Dialog fields test');   
    emplIdField = dialog.addField(typeId(emplid));
    dialog.run(true);
    dialog.formRun().controlMethodOverload(true);
    dialog.formRun().controlMethodOverloadObject(this);
    return  dialog;
}

public void Fld1_1_lookup()
{
    FormStringControl        control               = dialog.formRun().controlCallingMethod();
    SysTableLookup          sysTableLookup =  SysTableLookup::newParameters(tablenum(EmplTable), control);
    Query                         query                = new Query();
    QueryBuildDataSource                          queryBuildDataSource;
    EmplTable                                            EmplTable;
    ;
   
    sysTableLookup.addLookupfield(fieldnum(EmplTable, EmplId));
    sysTableLookup.addLookupfield(fieldnum(EmplTable,EmplIdentNumber ));
    queryBuildDataSource = query.addDataSource(tablenum(EmplTable));
    queryBuildDataSource.addRange(fieldnum(EmplTable,EmplId)).value(queryRange("1000","2000"));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

public static void main(Args args)
{
     TestDialogFields testDialogFields = new TestDialogFields();
     ;
     testDialogFields.showDialog();
}

How to open a a form on button click ?


void clicked()
{
    Menufunction       menufunction ;
    Args                    args = new Args();
    FormRun              formRun;
    ;
    
    if(MyTable.StatusId == " ")
    {
        throw error("Please fill the StatusId of the record ");
    }
    else
    {
    args.record(MyTable);
    menufunction  = new Menufunction(menuitemdisplaystr(MyTrans),menuItemType::Display);
    formRun         = menufunction.create(args);
    formRun.run();
    formRun.wait(true);
  
      }
   
}