Filter table using SELECT statement by list of referenced values

static void filterExample(Args _args)
{
    container       products = [22565421967, 22565421968, 22565421973, 22565421976];
    TmpRecIdFilter  tmpFilter;
    InventTable     inventTable;    
    
    TmpRecIdFilter getTmpFilterTable(container _referenceValues)
    {
        TmpRecIdFilter  tmpRecIdFilter;
        RefRecId        refRecId;
        int             length = conLen(_referenceValues),
                        i;

        for (i = 1; i <= length; i++)
        {
            refRecId = conPeek(_referenceValues, i);

            tmpRecIdFilter.RefRecId = refRecId;
            tmpRecIdFilter.doInsert();
        }

        return tmpRecIdFilter;
    }

    tmpFilter = getTmpFilterTable(products);
    
    while select inventTable
        join tmpFilter
            where inventTable.Product == tmpFilter.RefRecId
    {    
        abs(1);
    }
}
And a method using RecordInsertList. It should be executed only at server side, otherwise will fail with following error:
RecordInsertList or RecordSortedList operations are not allowed with database temporary tables.
static server TmpRecIdFilter getTmpFilterTableServer(container _referenceValues)
{
    TmpRecIdFilter      tmpRecIdFilter;
    RefRecId            refRecId;
    int                 length = conLen(_referenceValues),
                        i;
    RecordInsertList    invoicesToBeInserted = new RecordInsertList(    tableNum(TmpRecIdFilter), // table id
                                                                        true, // skip insert
                                                                        true, // skip database log
                                                                        true, // skip events
                                                                        true, // skip aos validation
                                                                        true, // skip RLS validation
                                                                        tmpRecIdFilter); // buffer where records will be inserted
    new SkipAOSValidationPermission().assert();
    for (i = 1; i <= length; i++)
    {
        refRecId                = conPeek(_referenceValues, i);
        tmpRecIdFilter.RefRecId = refRecId;
        invoicesToBeInserted.add(tmpRecIdFilter);
    }
    invoicesToBeInserted.insertDatabase();

    return tmpRecIdFilter;
}
Do not forget to clear CountryRegionCodes property on TmpRecIdFilter table.

 

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units and "buy me a coffee" link.
Join us.

Blog Tags