Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Query range expressions in AX

Posted on by 572

Hi Experts,

Can anyone help me to spot the mistake in the below query range expression. I need to filter the records with transtype == payment & Last settlevoucher  is empty. 

public void init()
{
QueryBuildDataSource qbds;
QueryBuildRange qbr;

super();

qbds = this.query().dataSourceTable(tableNum(VendTrans));


qbr = qbds.addRange(fieldNum(VendTrans,LastSettleVoucher));
qbr = qbds.addRange(fieldNum(VendTrans,TransType));

qbr.value(strFmt('((LastSettleVoucher == "%1") && (TransType == %2))',
queryValue(""),
queryValue(any2int(LedgerTransType::Payment))));

qbr.status(RangeStatus::Hidden);
}

pastedimage1658405798876v1.png

  • Rohit P Modani Profile Picture
    Rohit P Modani 15 on at
    RE: Query range expressions in AX

    Hi,

    You can try the solution mentioned by Ergun or try the below snippet.

    Just remove the "" from %1.

    qbr = qbds.addRange(fieldNum(VendTrans,LastSettleVoucher));
    qbr = qbds.addRange(fieldNum(VendTrans,TransType));
    qbr.value(strFmt('((LastSettleVoucher == %1) && (TransType == %2))',
    queryValue(""),
    queryValue(any2int(LedgerTransType::Payment))));

  • Verified answer
    ergun sahin Profile Picture
    ergun sahin 8,812 Super User 2024 Season 1 on at
    RE: Query range expressions in AX

    You don't need to get value with %1 for empty string. As a matter of fact, there is no need for you to use Expressions. If you give range values to the fields like below, such errors will not occur.

    Expressions are mostly used to write "or" clauses between multiple fields and create more complex structures.

    QueryBuildDataSource qbds;
        QueryBuildRange qbrSettle,qbrTransType;
        super();
    
        qbds = this.query().dataSourceTable(tableNum(VendTrans));
    
        qbrSettle = qbds.addRange(fieldNum(VendTrans,LastSettleVoucher));
        qbrSettle.value(SysQuery::valueEmptyString());
        
        qbrTransType = qbds.addRange(fieldNum(VendTrans,TransType));
        qbrTransType.value(sysquery::value(LedgerTransType::Payment));

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans