Sunday, June 30, 2013

Customize Caller Args

From the caller:
    Args args;
    Object formRun;
    args = new Args();
    args.name(formStr(BudgetModelLookup));
    args.caller(_ctrl);
    formRun = classfactory.formRunClass(args);
    formRun.init();
    _ctrl.performFormLookup(formRun);

With the pre-built form BudgetModelLookup
the caller's formRun.init() invokes callee's init method, as the callee is a form itself.
 public void init()
{
    FormStringControl callingControl;
    callingControl = SysTableLookup::getCallerStringControl(
        this.args());
    super();
    budgetModelTree = BudgetModelTree::construct(
        ModelTree,
        callingControl.text());
    budgetModelTree.buildTree();
}
The callee contruct and build the UI. After the callee's init, the process flow goes back to the caller's code, which performs lookup
 _ctrl.performFormLookup(formRun);

Saturday, June 29, 2013

NonExist Join

static void Job7(Args _args)
{
    container ret;
    container data;
    CustTable custTable;
    InventBuyerGroupList groupList;
    InventBuyerGroup inventBuyerGroup;
    while select custTable
        notExists join firstOnly groupList
        where groupList.CustAccount == custTable.AccountNum
        join inventBuyerGroup
        where
         groupList.GroupId == InventBuyerGroup.Group
    {
       
        data = [custTable.AccountNum,
        custTable.AccountNum,
        custTable.name()];
        ret = conIns(ret, conLen(ret)+1, data);      
    }
}

select custTable
        notExists join firstOnly groupList
        where groupList.CustAccount == custTable.AccountNum
select all customers whose account number does not exist in GroupList(InventBuyerGroupList ).

Friday, June 28, 2013

Create Seq Handler

Methods to be added on the datasource (override)

Form method
public NumberSeqFormHandler numberSeqFormHandler() { if (!numberSeqFormHandler) { numberSeqFormHandler = NumberSeqFormHandler::newForm( CustParameters::numRefCustGroupId().NumberSequenceId, element, CustGroup_ds, fieldNum(CustGroup,CustGroup)); } return numberSeqFormHandler; } Override Datasource
public void create(boolean _append = false) { element.numberSeqFormHandler().formMethodDatasourceCreatePre(); super(_append); element.numberSeqFormHandler().formMethodDatasourceCreate(); }
public void delete() { ttsBegin; element.numberSeqFormHandler().formMethodDatasourceDelete(); super(); ttsCommit; }
public void write() { ttsBegin; super(); element.numberSeqFormHandler().formMethodDatasourceWrite(); ttsCommit; }
public boolean validateWrite() { boolean ret; ret = super(); ret = element.numberSeqFormHandler().formMethodDatasourceValidateWrite(ret) && ret; return ret; }
public void linkActive() { element.numberSeqFormHandler().formMethodDatasourceLinkActive(); super(); }
override form method public void close() { if (numberSeqFormHandler) { numberSeqFormHandler.formMethodClose(); } super(); }

Generate Number Seq

User CustGroupId as an example,
add code to class: NumberSeqModuleCustomer
    datatype.parmDatatypeId(extendedTypeNum(CustGroupId));
    datatype.parmReferenceHelp("Customer group ID");
    datatype.parmWizardIsContinuous(false);
    datatype.parmWizardIsManual(NoYes::No);
    datatype.parmWizardIsChangeDownAllowed(NoYes::Yes);
    datatype.parmWizardIsChangeUpAllowed(NoYes::Yes);
    datatype.parmWizardHighest(999);
    datatype.parmSortField(20);
    datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
    this.create(datatype);

Locate Table: CustParameters, add a new method to this table.
public server static NumberSequenceReference numRefCustGroupId()
{
    return NumberSeqReference::findReference(
    extendedTypeNum(CustGroupId));
}
To Test the sequence generated, create a job as the following:
static void number(Args _args)
{
    NumberSeq  numberSeq;
    CarId num;
    ;
    numberSeq = NumberSeq::newGetNum(CustParameters::numRefCustGroupId());
    num = numberSeq.num();
    info(num);
}
 

Wednesday, June 26, 2013

LinkType

The LinkType property determines how two data sources
are joined. The following list describes each option:
• Passive: The query on the joined data source is only
executed when the form is opened. A later change in the
controlling data source does not change the view.
• Delayed: The query on the joined data source is
executed every time that the controlling data source is
changed. The query execution is delayed to avoid the
fetch of data, if the controlling data source is changed
multiple times in a short time. This is the case when the
user is scrolling through data on a grid.
• Active: This option is similar to Delayed, except there is
no delay before the query is executed.
• InnerJoin: Selects records from the main table that have
matching records in the joined table and vice versa. If
the joined table does not have any records related to the
main table record, the main table record is not
displayed. Each match returns a result set of the main
table record and joined table record joined together as
one record. This is useful when wanting to display
records from both tables in a grid.
• OuterJoin: Selects records from the main table whether
they have matching records in the joined table. Each
match returns a result set of the main table record and
joined table record joined together as one record. If
there is no match, the fields from the joined table will be
empty.
• ExistsJoin: Selects a record from the main table only if
there is a matching record in the joined table. As soon as
a matching record is found, the main table record is
returned. The record in the joined table is never
retrieved.
• NotExistsJoin: Select records from the main table that
do not have a match in the joined table.

Tuesday, June 25, 2013

Map

    Map mapStateNumbers;
    MapEnumerator enumerator;
    CustTable custTable;
    mapStateNumbers = new Map(Types::String, Types::Integer);
    while select custTable
    {
        if(mapStateNumbers.exists(custTable.stateName()))
        {
        mapStateNumbers.insert(custTable.stateName(), mapStateNumbers.lookup(custTable.stateName())+1);
        }
        else
        {
        mapStateNumbers.insert(custTable.StateName(), 1);
        }
    }
    enumerator = mapStateNumbers.getEnumerator();
    while (enumerator.moveNext())
    {
        info(strfmt("%1 customers are located in %2.", enumerator.currentValue(), enumerator.currentKey()));
    }

Write a text file

    FileName fileName = 'c:\\test.txt';
    FileIoPermission permission;
    FileIO fileIO;
    str outputText;
    #File
    ;
    permission= new FileIoPermission(filename,#io_write);
    permission.assert();
    fileIO= new FileIO(filename, #io_write);
    if (fileIO)
    {
        outputText = "text that will go into the text file.";
        fileIO.write(outputText); //write the text to the file.
        fileIO.finalize(); //finish the file.
    }