17 Haziran 2014 Salı

AX 2012 - Sysoperation class sample

Contract Class:
classDeclaration method:

[DataContractAttribute]
class myTestContract
{
    TransDate       transDate;
    str             packedQuery;
    LedgerJournalId JournalId;
}


Other methods:
//------ for get Query  -------------
public Query getQuery()
{
    return new Query(SysOperationHelper::base64Decode(packedQuery));
}


//---------- parm method sample --------------
[DataMemberAttribute
, SysOperationControlVisibilityAttribute(false)]
public LedgerJournalId parmJournalId(LedgerJournalId _JournalId = JournalId)
{
    JournalId = _JournalId;

    return JournalId;
}

//--------------------- call query with parmQuery  ----------------
[DataMemberAttribute,
    AifQueryTypeAttribute('_packedQuery', querystr(myQuery))
]
public str parmQuery(str _packedQuery = packedQuery)
{
    packedQuery = _packedQuery;
    return packedQuery;
}

//-------------- send query with SetQuery -----------------------
public void setQuery(Query _query)
{
    packedQuery = SysOperationHelper::base64Encode(_query.pack());
}



DataService Class:

ClassDeclaration metodu:
class myDataService
{
}


Batch job method:

[SysEntryPointAttribute]
public void Go(myContract _contract)
{
    QueryRun                            qRun;
    Query                               query;
    QueryBuildDataSource                QBDS;
    QueryBuildRange                     QBR,QBR2;
    CustTable               CustTable;
    LedgerJournalId                     JournalId;
    TransDate                           PaymDate;
    LedgerJournalTrans                  journalTrans;

    JournalId = _contract.parmJournalId();
 

    query = _contract.getQuery();
    QBDS = query.dataSourceTable(tablenum(CustTable));
    QBR = QBDS.findRange(fieldnum(CustTable,CustAccount));
    if (!QBR)
        QBR = QBDS.addRange(fieldnum(CustTable,CustAccount));
    QBR.value(queryValue("000001"));

    qRun = new QueryRun(query);

    while(qRun.next())
    {
        CustTable = qRun.get(tableNum(CustTable));
      ...
    }


Controller Class:
class declaration:
 

class MyController extends SysOperationServiceController
{
}


public static MyController newFromArgs(Args _args)
{
    MyController    controller;
    MyContract      contract;
    LedgerJournalTable             LedgerJournalTable;

    if ( !_args || !_args.caller() )
        throw error("This class needs parameter!..");

    ledgerJournalTable = _args.caller().ledgerJournalTable();
    controller = new ETGVendAdvanceReqController();

    controller.initializeFromArgs(_args);

    contract = Controller.getDataContractObject("_contract");
    contract.parmPaymDate(today());
    contract.parmJournalId(ledgerJournalTable.JournalNum);

    return Controller;
}


public static void main(Args _args)
{
    MyController controller;

    controller = MyController::newFromArgs(_args);

    controller.parmExecutionMode(SysOperationExecutionMode::Asynchronous);
    controller.startOperation();
}

 
Menu item parameters:

Object - MyController
ObjectType - class
Parameters - MyDataService.Go 

Hiç yorum yok:

Yorum Gönder