Thursday, May 5, 2016

Print table fields

static void PrintTableFieldName(Args _args)
{
    SysDictTable    dictTable = SysDictTable::newTableId(tableNum(CustParameters));
    SysDictField    dictField;
    Set             fields = dictTable.fields(true, true, true);
    SetEnumerator   setEnum = fields.getEnumerator();

    while (setEnum.moveNext())
    {
        dictField = setEnum.current();
        info(dictField.label());
    }
}

Tuesday, May 3, 2016

Example of how to handle formdatasource multiselection through args:

public static void main(Args _args)
{
    Common                  record = _args.record();
    FormDataSource          fds;
    MultiSelectionHelper    multiSelectionHelper;

    if(!record || !record.dataSource())
        throw error(Error::wrongUseOfFunction(funcName()));

    fds = record.dataSource();

    multiSelectionHelper = MultiSelectionHelper::construct();
    multiSelectionHelper.parmDatasource(fds);

    record = multiSelectionHelper.getFirst();
    while (record)
    {
        // function here
        record = multiSelectionHelper.getNext();
    }
}

Send via AIF multiple records to outbound file

If you have a requirement to send more than one record per XML as an outbound, then have a look on the following job:
static void AifSendCustomerFromQuery(Args _args)
{
    AxdSendContext                  axdSendContext      = AxdSendContext::construct();
    AifAction                       aifAction;
    AifConstraint                   aifConstraint       = new AifConstraint();
    AifConstraintList               aifConstraintList   = new AifConstraintList();
    AifOutboundProcessingService    aifOutboundProcessingService = new AifOutboundProcessingService();
    AifGatewaySendService           aifGatewaySendService = new AifGatewaySendService();
    AifActionId                     actionId;
    AifEndpointList                 endpointList;
    Query                           query;
    QueryBuildDataSource            queryBuildDataSource;
    ;

    query = new Query(queryStr(AxdCustomer));
    AxdSend::removeChildDs(query);
    queryBuildDataSource = query.dataSourceTable(tablenum(CustTable));
    queryBuildDataSource.addRange(fieldnum(CustTable, RecId));
    queryBuildDataSource.rangeField(fieldnum(CustTable, RecId)).value(strfmt('5637144577..5637144587'));

    aifAction = AifAction::find(AifSendService::getDefaultSendAction(
                                                        classnum(CustCustomerService), 
                                                        AifSendActionType::SendByQuery));

    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);

    aifConstraint.parmType(AifConstraintType::NoConstraint);
    aifConstraintList.addConstraint(aifConstraint) ;

    endPointList = AifSendService::getEligibleEndpoints(aifAction.ActionId,aifConstraintList);

    AifSendService::submitFromQuery(aifAction.ActionId, endpointList, query, AifSendMode::Sync);

    AifGatewaySendService.run();
    AifOutboundProcessingService.run();
}