Skip to main content

Notifications

Announcements

No record found.

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

AOT Query range on one column with OR condition of another column.

(0) ShareShare
ReportReport
Posted on by 438

Hi All,
Is there any possibilities to add AOT query range with OR condition with 2 different fields on one field ?

Like Below: 

( salesTable.DocumentStatus = None || (salesTable.DocumentStatus != None && salesTable.TestConfirmationStatus = ToBeConfirmed ))

Description: I am developing a workspace form and there i want to show the count of sales order with above conditions. 
pastedimage1671779387151v1.png
pastedimage1671779505165v2.png

  • Martin Dráb Profile Picture
    Martin Dráb 230,354 Most Valuable Professional on at
    RE: AOT Query range on one column with OR condition of another column.

    You're missing out-most parentheses.

    Another problem is that data source may have different names than tables. Use name() method of QueryBuildDataSource instead of tableStr().

    Hard-coding enum elements numbers is a bad idea, and it may give you completely wrong result if any of the enums if extensible. Use enums instead, such as DocumentStatus::None instead of 0.

    Correct me if I'm wrong, but I don't think you need the check for DocumentStatus != DocumentStatus::None.

  • Vijay Yelmame VY Profile Picture
    Vijay Yelmame VY 438 on at
    RE: AOT Query range on one column with OR condition of another column.

    Thank Martin for your help. I am now able to filter on the query. by adding range like below.

    (DOCUMENTSTATUS == 0),(DOCUMENTSTATUS != 0 && TESTCONFIRMATIONSTATUS == 1)
    pastedimage1671807447580v1.png

    I am trying to add similar range from X query on form DataSource but not sure why it is not working. Even in the info as well i am getting below query but my form DataSource is not filtering the record according to this query.

    SELECT FIRSTFAST FORUPDATE * FROM NCABAllSOLinesView(TESTAllSOLinesView) WHERE (((TESTAllSOLinesView.DocumentStatus == "0") || ((TESTAllSOLinesView.NCABConfirmationStatus == "1") && (TESTAllSOLinesView.DocumentStatus != "0"))))

    Below code is in the data source execute query.

    this.query().dataSourceTable(tableNum(TESTAllSOLinesView)).addRange(fieldNum(TESTAllSOLinesView,DocumentStatus)).value(
        strFmt('(%1.%2 == "0") || ((%1.%3 == "1") && (%1.%2 != "0"))',tableStr(TESTAllSOLinesView),fieldStr(TESTAllSOLinesView, DocumentStatus),fieldStr(TESTAllSOLinesView, TESTConfirmationStatus)));
        
        Query q2 = new Query(this.query());
    
        info(strfmt("%1",q2));

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,354 Most Valuable Professional on at
    RE: AOT Query range on one column with OR condition of another column.

    You should be able to use something like this:

    ((DocumentStatus = DocumentStatus::None) || (TestConfirmationStatus = YourEnum::ToBeConfirmed))

    You can find quite a few examples in existing queries, such as PurchRFQAllReplySummary_PSN:

    4370.query.jpg

  • GirishS Profile Picture
    GirishS 27,816 Super User 2024 Season 1 on at
    RE: AOT Query range on one column with OR condition of another column.

    Hi Vijay Yelmame,

    I don't think you can add range with multiple fields in one range.

    It will be better if you can add above range in the workspace form through code.

    Thanks,

    Girish S.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans