Friday, 17 October 2014

RunBase framework

RunBase framework:


The RunBaseBatch class extends the RunBase class and allows one to create classes (jobs) that can be added to the batch queue. Once the job has been added to the queue, it will be executed by the batch server. This concept is known as batch processing.

Whenever you write a class that typically asks a user for input and then starts a process based on that input you use the RunBase framework as most of the typical methods needed for such a Job is already implemented in the RunBase class. This means that using the RunBase framework is done by extending RunBase either by directly extending RunBase or by extending a class that extends RunBase.

For more: RunBase

Some of the features implemented in the RunBase framework are the following:

• Run: The main flow of the operation

• Dialog: Prompting the user for input and storing that input

• Batch execution: Schedule the Job for later execution

• Query: Used to select data

• Progress bar: Shows the progress of a task

• Pack/unpack with versioning: Remember variable values until the next time

the task is executed              

Pack and Unpack method:This method is a standard method inherited from RunBase. It is used to save
the values that the user selects and store them until the next time the user executes
the class.
public container pack()
{
    ;
    return [#CurrentVersion,#CurrentList];// + [super()];
}
And under unpack:

public boolean unpack(container packedClass)
{
    container       _base;
    boolean         _ret;
    Integer         _version    = conpeek(packedClass,1);
    switch (_version)
    {
        case #CurrentVersion:
            [_version, #CurrentList, _base] = packedClass;
            //_ret = super(_base);
            break;
        default:
            _ret = false;
    }
    return _ret;
}
And your class declaration looks like:

class ItemCreationApprove extends runbase
{
    Dialogfield fieldapprover;
    approvedby  approver;
    #define.CurrentVersion(2)
    #localmacro.CurrentList
        approver
    #endmacro
}
Other framework in Microsoft dynamics AX:

Ø  Runbase Framework

Ø  Batch Framework

Ø  Dialog Framework

Ø  Operation Progress Framework 

Ø  NumberSequence Framework

Ø  SysLastValue Framework

Ø  AIF-Application Integration Framework

Ø  Wizard Framework

Ø  Infolog Framework

Ø  Unit Test Framework

=============================================================

Demo : Use Query created in AOT and update a table using batch
class SalesFactoringBatch extends RunBaseBatch
{
    SysQueryRun                    queryRun;
    DialogRunbase               dialog;

    #DEFINE.CurrentVersion(1)
}

[
SysEntryPointAttribute(true)
]
public void run()
{
    CustTrans       custTrans; 
    if (! this.validate())
        throw error("");

    while (queryRun.next())
    {
        custTrans   = queryRun.get(tableNum(custTrans));
        ttsBegin;
        custTrans.selectForUpdate(true);
        custTrans.CustFactored = NoYes::Yes;
        custTrans.update();
        ttsCommit;
    }
}

protected Object dialog()
{
     dialog          =  super();
//Shows query in Dialog,( new DialogRunbase("@CIT277", this); Will //hide query
    return dialog;
}

public boolean canGoBatchJournal()
{
    return true;
}

public void new()
{
    super();
    queryRun = new SysQueryRun(querystr(SalesFactoringQuery));
}

public container pack()
{   
    return [#CurrentVersion, queryRun.pack()];
}
public QueryRun queryRun()
{
    return queryRun;
}
boolean unpack(container packedClass)
{

    Integer             version        = conpeek(packedClass,1);
    container           packedQuery;

    switch (version)
    {
        case #CurrentVersion:
            [version,packedQuery] = packedClass;
            if (packedQuery)
                queryRun = new SysQueryRun(packedQuery);
            break;

        default:
            return false;
    }
    return true;
}
public boolean validate(Object _calledFrom = null)
{
    if (false)
        return checkFailed("");

    return true;
}

public static SalesFactoringBatch construct()
{
    return new SalesFactoringBatch();
}

public static void main(Args _args)
{
    SalesFactoringBatch _salesFactoringBatch;
    _salesFactoringBatch = SalesFactoringBatch::construct();
    if(_salesFactoringBatch.prompt())
    {
        _salesFactoringBatch.run();
    }
}
public void initParmDefault()
{

    Query query;
    ;
    super();
    query = new Query(queryStr(SalesFactoringQuery));
    queryRun = new QueryRun(query);
}
public boolean showQueryValues()
{
    boolean ret;
    ret =  true;
    return ret;
}
public ClassDescription caption()
{
//To get caption
    return "@NCC124";

}


http://daxtechies.blogspot.in/2013/12/dialog-in-ax-2012-multiselect-control.html

https://community.dynamics.com/ax/b/dynamicsaxinsightbyanas/archive/2015/04/22/ax-2012-add-lookup-to-batch-job-dialog

No comments:

Post a Comment