Sunday, 12 April 2015

AIF adding the range for Mutiple records in ax 2012

static void AIFSendRange(Args _args)
{
AxdSendContext                 axdSendContext = AxdSendContext::construct();
AifConstraint                      aifConstraint = new AifConstraint() ;
AifConstraintList                aifConstraintList = new AifConstraintList();
AifActionId                         actionId;
AifEndpointList                  endpointList;

Query                                  query;
QueryBuildDataSource       queryBuildDataSource;
QueryBuildRange               qbr;
RecId                                   start;
RecId                                   end;
LedgerTable                        ledgerTable;
;

//reading lowest recordId for a specific criteria
select firstonly RecId from ledgerTable where ledgerTable.AccountPlType == LedgerAccountType::Heading;

start = ledgerTable.RecId;
end = start + 100;          // add some value to the recordId. This increment value we can change depends on req.

query = new Query(queryStr(AxdChartOfAccounts));
AxdSend::removeChildDs(query);

queryBuildDataSource = query.dataSourceTable(tablenum(LedgerTable));
queryBuildDataSource.addRange(fieldnum(LedgerTable, AccountPlType)).value(QueryValue(LedgerAccountType::Heading));

qbr = queryBuildDataSource.addRange(fieldnum(LedgerTable, RecId));

//here adding the records range condition, to filter the no.of records to send in XML
qbr.value(strfmt(‘( (%1 >= %2) && (%1 <= %3) )’,fieldstr(LedgerTable, RecId),start,end));

actionId = AifSendService::getDefaultSendAction(classnum(LedgerChartOfAccountsService), AifSendActionType::SendByQuery);

aifConstraint.parmType(AifConstraintType::NoConstraint);
aifConstraintList.addConstraint(aifConstraint);
endpointList = AifSendService::getEligibleEndpoints(actionId, aifConstraintList);

//implemented the AIF-Outbound using query object
AifSendService::submitFromQuery(actionId, endpointList, query, AifSendMode::Async);
}

No comments:

Post a Comment