17 Haziran 2014 Salı

AX - 2012 Sysoperation class örneği

Contract Class:
classDeclaration metodu:

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


Diğer metodlar:
//------ Query almak için -------------
public Query getQuery()
{
    return new Query(SysOperationHelper::base64Decode(packedQuery));
}


//---------- bir parm metod örneği --------------
[DataMemberAttribute
, SysOperationControlVisibilityAttribute(false)]
public LedgerJournalId parmJournalId(LedgerJournalId _JournalId = JournalId)
{
    JournalId = _JournalId;

    return JournalId;
}

//--------------------- parmQuery ile bir query çağır ----------------
[DataMemberAttribute,
    AifQueryTypeAttribute('_packedQuery', querystr(myQuery))
]
public str parmQuery(str _packedQuery = packedQuery)
{
    packedQuery = _packedQuery;
    return packedQuery;
}

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



DataService Class:


ClassDeclaration metodu:
class myDataService
{
}


Batch job metodu:

[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 parametreleri:

Object - MyController
ObjectType - class
Parameters - MyDataService.Go 

Hiç yorum yok:

Yorum Gönderme