Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to create the following while select into an x++ query

Posted on by Microsoft Employee

How to create the following while select  into an x++ query,

z_RentalOrderTable rent;
TransDate                td = today() - 7;

while select firstonly100 rent order by PostedDate desc

where (rent.PostedDate > td && rent.RentalOrderStatus == z_RentalOrderStatus::Posted)

  || rent.RentalOrderStatus == z_RentalOrderStatus::Approved

{

info("orders");

}

I want the (posted orders from the past week or approved order of any date) in the output.

I tried the following, 

this.query().dataSourceTable(tableNum(z_RentalOrderTable)).addrange(fieldNum(z_RentalOrderTable,Rentalorderstatus)).value(strfmt('(((%1 = %2) && (%3 > %4)) || (%5 = %6))',
fieldStr(z_RentalOrderTable,Rentalorderstatus),
any2int(z_RentalOrderStatus::Posted),
fieldStr(z_RentalOrderTable,PostedDate),
dateRange,
fieldStr(z_RentalOrderTable,Rentalorderstatus),
any2int(z_RentalOrderStatus::Approved)));

This didn't work. its showing approved orders and ( posted orders with no control on its date)

Please help.

Thanks ,

Praveen

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to create the following while select into an x++ query

    Thank you so much Martin, you are awesome. It worked. Date was the problem.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: How to create the following while select into an x++ query

    Okay, that's likely the problem. Convert the date to string with date2StrXpp().

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to create the following while select into an x++ query

    Martin,

    today() - 7 is the dateRange. its a date variable.

  • Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: How to create the following while select into an x++ query

    Let me make your code a bit more readable. Next time, please use the </> button in the rich formatting view and try to arrange your code to be as clear as possible.

    while select firstonly100 rent
        order by PostedDate desc
        where (rent.PostedDate > td && rent.RentalOrderStatus == z_RentalOrderStatus::Posted)
           || rent.RentalOrderStatus == z_RentalOrderStatus::Approved
    {
        info("orders");
    }
    QueryBuildRange range = this.query().dataSourceTable(tableNum(z_RentalOrderTable)).addRange(fieldNum(z_RentalOrderTable, RentalOrderStatus));
    
    range.value(strfmt('(((%1 = %2) && (%3 > %4)) || (%1 = %5))',
        fieldStr(z_RentalOrderTable, RentalOrderStatus),
        any2int(z_RentalOrderStatus::Posted),
        fieldStr(z_RentalOrderTable, PostedDate),
        dateRange,
        any2int(z_RentalOrderStatus::Approved)));

    What's the value of dateRange?

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to create the following while select into an x++ query

    Hi!

    This link will be helpful https://docs.microsoft.com/en-us/dynamicsax-2012/developer/using-expressions-in-query-ranges

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans