web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

how to add multiples enum values to filter in QBDS range.

(0) ShareShare
ReportReport
Posted on by 30

Hi Team, 

Kindly let me know how to add multiples type from retailTransactionTable in qbds range.

The typw will be Income expense, float entry, Remove tender

Query                   query   = new Query();
        QueryRun                queryRun;
        QueryBuildDataSource    qbds;

        qbds = query.addDataSource(tableNum(RetailTransactionTable));
        qbds.addRange(fieldNum(RetailTransactionTable, TransDate)).value(SysQuery::range(fromDate, toDate));
        qbds.addRange(fieldNum(RetailTransactionTable, store)).value(con2Str(stores));
        // TO DO
        // LIKE to put range based on type like Income expense, float entry, Remove tender***********

        queryRun    = new queryrun(query);

        while (queryRun.next())
        {
            retailTransactionTable     = queryRun.get(tablenum(RetailTransactionTable));
        }
}        }

Kindly send me the syntax pls.

Pls give me more shed on this.

thanks!

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, You can add range on the Transaction Type Field

    QueryBuildRange qbr = qbds.addRange(fieldNum(RetailTransactionTable, TransactionType));
    
    qbr.value(strFmt('((TransactionType == %1) || (TransactionType == %2))', any2int(TransactionType::Income), any2int(TransactionType::Expense)));

    vimalaxapta.blogspot.com/.../how-to-add-set-multiple-enum-values-in.html

    https://erpdax.wordpress.com/tag/query-range/

  • @rp@n Profile Picture
    30 on at

    Hi Mohit,

    I tried the above expression but report is totally hanged. 

    I don't wants to considered other elements in my report unnecessary in loop. just to be considered only those 3 transactionType in my report.

    I have debugged the query return the below ouput. It seems correct only I guess

    {Query  object 890528b0: SELECT * FROM RetailTransactionTable(RetailTransactionTable_1) ORDER BY RetailTransactionTable.type ASC WHERE 
    ((transDate>={ts '2022-12-20 00:00:00.000'} AND transDate<={ts '2022-12-20 00:00:00.000'})) AND ((store = N'104096')) AND 
    ((((TransactionType == Income expense) || (TransactionType == Float entry) || (TransactionType == Remove tender))))}

    pastedimage1683904471396v1.png

    The Type = 0 for RetailTransactionType::LogOff

    got the below message

    pastedimage1683904905637v1.png

    Here the transaction type unnecessary taking the element 0 that' s I don't want to enter in the loop.

    I just looking for only above mentioned 3 transactions type which I needed only to considered in my report,

    Kindly let me know what to modify?

    Pls give me more shed on this.

    thanks! 

  • @rp@n Profile Picture
    30 on at

    Hi Mohit,

    Here is my complete code

    AmicisPayInTable                    payInTable;
            RetailTransactionTable              retailTransactionTable;
            RetailTransactionPaymentTrans       retailTransactionPaymentTrans;
            RetailTransactionInfocodeTrans      retailTransactionInfoCodeTrans;
            RetailTransactionIncomeExpenseTrans retailTransactionIncomeExpenseTrans;
            RetailIncomeExpenseAccountTable     retailIncomeExpenseAccountTable;
    
            RetailStoreId                       wareHouse;
            TransDate                           payDate;
            Amount                              amount;
            RetailInfocodeId                    driverId;
            Name                                driverName;
            RetailInfocodeInformation           bagNumber;
            RetailTransactionType               type;
    
            Query                   query   = new Query();
            QueryRun                queryRun;
            QueryBuildDataSource    qbds;
            QueryBuildRange         qbr;
    
            qbds = query.addDataSource(tableNum(RetailTransactionTable));
            qbds.addRange(fieldNum(RetailTransactionTable, TransDate)).value(SysQuery::range(fromDate, toDate));
            qbds.addRange(fieldNum(RetailTransactionTable, store)).value(con2Str(stores));
            qbr = qbds.addRange(fieldNum(RetailTransactionTable,Type));
            qbr.value(strFmt('((TransactionType == %1) || (TransactionType == %2) || (TransactionType == %3))',
                (RetailTransactionType::IncomeExpense), (RetailTransactionType::FloatEntry), (RetailTransactionType::RemoveTender)));
            qbds.addSortField(fieldNum(RetailTransactionTable, Type),SortOrder::Ascending);
            
            queryRun    = new queryrun(query);
    
            while (queryRun.next())
            {
                retailTransactionTable     = queryRun.get(tablenum(RetailTransactionTable));
    
                type        = retailTransactionTable.type;                        
    
                
                    wareHouse   = retailTransactionTable.store;
                    payDate     = retailTransactionTable.transDate;
    
                    select * from retailTransactionIncomeExpenseTrans
                        where retailTransactionIncomeExpenseTrans.terminal == retailTransactionTable.terminal
                        &&    retailTransactionIncomeExpenseTrans.store == retailTransactionTable.store
                        &&    retailTransactionIncomeExpenseTrans.transactionId == retailTransactionTable.transactionId;
    
                    // In the case of paid in - amount should be visible as positive. In the case of the paid out- amount should be visible as negative.
                    if (retailTransactionIncomeExpenseTrans)
                    {
                        // to do
                        amount = retailTransactionIncomeExpenseTrans.amount;
                    }
    
                    select * from retailTransactionInfoCodeTrans
                        where retailTransactionInfoCodeTrans.terminal == retailTransactionTable.terminal
                        &&    retailTransactionInfoCodeTrans.store == retailTransactionTable.store
                        &&    retailTransactionInfoCodeTrans.transactionId == retailTransactionTable.transactionId;
    
                    if (retailTransactionInfoCodeTrans)
                    {
                        driverId = retailTransactionInfoCodeTrans.infocodeId;
                        //driverName =
                        bagNumber = retailTransactionInfoCodeTrans.information;
                    }
    
                   // Tmp table data insert
                    payInTable.clear();
    
                    payInTable.Store = wareHouse;
                    payInTable.PayDate = payDate;
                    payInTable.Amount = amount;
                    
                    payInTable.insert();
                
        }         

    Pls give me more shed on this.

    thanks!

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, if you check the code I provided has any2int in qbr.value in my enum values. Please apply it and try again.

  • Verified answer
    Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at

    You should avoid the extended query syntax unless necessary, because it's difficult to write and debug. It's not needed in your case; simply add three ranges for the same field:

    qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::IncomeExpense));
    qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::FloatEntry));
    qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::RemoveTender));

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Martin's code should work, also you can check this old thread.

    community.dynamics.com/.../how-to-use-multiple-enum-values-as-query-filter

  • @rp@n Profile Picture
    30 on at

    Hi Martin & Mohit

    Thanks for your support. I applied Martin's suggestions and it is working as expected

    AmicisPayInTable                    payInTable;
            RetailTransactionTable              retailTransactionTable;
            RetailTransactionPaymentTrans       retailTransactionPaymentTrans;
            RetailTransactionInfocodeTrans      retailTransactionInfoCodeTrans;
            RetailTransactionIncomeExpenseTrans retailTransactionIncomeExpenseTrans;
            RetailIncomeExpenseAccountTable     retailIncomeExpenseAccountTable;
    
            RetailStoreId                       wareHouse;
            TransDate                           payDate;
            Amount                              amount;
            RetailInfocodeId                    driverId;
            Name                                driverName;
            RetailInfocodeInformation           bagNumber;
            RetailTransactionType               type;
    
            Query                   query   = new Query();
            QueryRun                queryRun;
            QueryBuildDataSource    qbds;
            QueryBuildRange         qbr;
    
            qbds = query.addDataSource(tableNum(RetailTransactionTable));
            qbds.addRange(fieldNum(RetailTransactionTable, TransDate)).value(SysQuery::range(fromDate, toDate));
            qbds.addRange(fieldNum(RetailTransactionTable, store)).value(con2Str(stores));
            qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::IncomeExpense));
            qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::FloatEntry));
            qbds.addRange(fieldNum(RetailTransactionTable, Type)).value(queryValue(RetailTransactionType::RemoveTender));
           
            qbds.addSortField(fieldNum(RetailTransactionTable, Type),SortOrder::Ascending);
            
            queryRun    = new queryrun(query);
    
            while (queryRun.next())
            {
                retailTransactionTable     = queryRun.get(tablenum(RetailTransactionTable));
    
                type        = retailTransactionTable.type;                        
                
                wareHouse   = retailTransactionTable.store;
                payDate     = retailTransactionTable.transDate;
    
                select * from retailTransactionIncomeExpenseTrans
                    where retailTransactionIncomeExpenseTrans.terminal == retailTransactionTable.terminal
                    &&    retailTransactionIncomeExpenseTrans.store == retailTransactionTable.store
                    &&    retailTransactionIncomeExpenseTrans.transactionId == retailTransactionTable.transactionId;
    
                // In the case of paid in - amount should be visible as positive. In the case of the paid out- amount should be visible as negative.
                if (retailTransactionIncomeExpenseTrans)
                {
                    // to do
                    amount = retailTransactionIncomeExpenseTrans.amount;
                }
    
                select * from retailTransactionInfoCodeTrans
                    where retailTransactionInfoCodeTrans.terminal == retailTransactionTable.terminal
                    &&    retailTransactionInfoCodeTrans.store == retailTransactionTable.store
                    &&    retailTransactionInfoCodeTrans.transactionId == retailTransactionTable.transactionId;
    
                if (retailTransactionInfoCodeTrans)
                {
                    driverId = retailTransactionInfoCodeTrans.infocodeId;
                    //driverName =
                    bagNumber = retailTransactionInfoCodeTrans.information;
                }
    
                payInTable.clear();
    
                payInTable.Store = wareHouse;
                payInTable.PayDate = payDate;
                payInTable.Amount = amount;
                
                payInTable.insert();
        }

    Debugger Output - Query returned

    {Query  object 874f5570: SELECT * FROM RetailTransactionTable(RetailTransactionTable_1) 
    ORDER BY RetailTransactionTable.type ASC 
    WHERE ((transDate>={ts '2022-12-20 00:00:00.000'} AND transDate<={ts '2022-12-20 00:00:00.000'})) 
    AND ((store = N'104096')) AND ((type = 18) OR (type = 5) OR (type = 4))}

    Thanks !

  • @rp@n Profile Picture
    30 on at

    Hi Mohit & Martin

    I have one another table RetailTransactionPyementTrans. In this table, one field is there tender type.

    The requirement is , if the value is 9 in tender type than that transaction should not considered in report.

    How will i add this table to qbds with range.

    pls give me more she don this.

    thanks!

  • Verified answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    You didn't provided much information on RetailTransactionPyementTranstable, I am assuming it has relation with RetailTransactionTable table and TenderType is a string field. You can declare one more variable qbds1 next to qbds in your code.

    qbds1 = qbds.addDataSource(tableNum(RetailTransactionPyementTrans));
    qbds1.relations(true);
    qbds1.addRange(fieldNum(RetailTransactionPyementTrans, TenderType)).value(SysQuery::valueNot("9"));

  • @rp@n Profile Picture
    30 on at

    Thanks Mohit for the reply.

    I have debugged and it seems  correct as the below output. It made relationsautomatically  and build the range accordingly

    
    
    {Query  object 897960a0: SELECT * FROM RetailTransactionTable(RetailTransactionTable_1) 
    ORDER BY RetailTransactionTable.type ASC 
    WHERE ((transDate>={ts '2022-12-20 00:00:00.000'} AND transDate<={ts '2022-12-20 00:00:00.000'})) 
    AND ((store = N'104096')) AND ((type = 18) OR (type = 5) OR (type = 4)) 
    JOIN * FROM RetailTransactionPaymentTrans(RetailTransactionPaymentTrans_1) 
    ON RetailTransactionTable.Channel = RetailTransactionPaymentTrans.Channel 
    AND RetailTransactionTable.store = RetailTransactionPaymentTrans.store 
    AND RetailTransactionTable.terminal = RetailTransactionPaymentTrans.terminal 
    AND RetailTransactionTable.transactionId = RetailTransactionPaymentTrans.transactionId 
    AND ((NOT (tenderType = N'9')))}

    thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans