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

Community site session details

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

Query range expressions in AX

(0) ShareShare
ReportReport
Posted on by 618

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

I have the same question (0)
  • Verified answer
    ergun sahin Profile Picture
    8,824 Moderator 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));

  • Rohit P Modani Profile Picture
    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))));

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,004

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 548 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans