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 :
Microsoft Dynamics AX (Archived)

Query Range not working at runtime

(0) ShareShare
ReportReport
Posted on by 180

Hi,


I have a situation where i have created a query in AX in the AOT with 5 different tables and relations etc...

I have linked this query to a view which i use in my processReport class to populate a temp table.

When i hard code a value in a range on one of the tables in the query (putting the value in on the property page) and run my report, the range is applied. when i apply the same range & value at runtime, it does not apply the range.


What could cause this ?

Thanks,

Adrian

*This post is locked for comments

I have the same question (0)
  • venkatesh vadlamani Profile Picture
    3,180 on at

    Need some more details to be of any help.Can you post the code that you wrote

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    "at runtime, it does not apply the range."

     

    are you trying to add range inside RDP..???

    if yes, how you are trying to add? give use some clue/details to think about reason

  • Adriano.85 Profile Picture
    180 on at

    Hi Venkatesh,

    Here is an adapted version of the code.

    public void processReport()

    {

       MyContract              myContract;

       DetailSummary                   printDetail;

       PurchTable                      purchTable;

       PurchLine    purchLine;

       VendTable    vendTable;

       MarkupTrans                     markupTrans;

       ExchangeRateHelper              exchangeRateHelper;

       DefaultDimensionView            defaultDimensionView;

       MyView                myView;

       myContract = this.parmDataContract() as MyContract;

       printDetail = myContract.parmPrintDetail();

       if (MyContract.parmasAtDate() == Global::DateNull())

       {

           throw error("As at date needs to be filled in");

       }

       ttsbegin;

       MyTempTmp(this.parmUserConnection());

       insert_recordset MyTempTmp(AField1,AField2,AField3,AFlield4,AField5)

       select BField1,BField2,BField3

           from myView

           //Ranges of the report

           where myView.BField2 <= MyContract.parmasAtDate()

                   && myView.BField2 > mkDate(01,01,1900);

       while select forUpdate * from myTempTmp

       {

           // Get exchange rate

           if (myTempTmp.AField2 == Global::DateNull())

           {

               myTempTmp.ExchangeRate = 1;

           }

           else

           {

                   exchangeRateHelper = ExchangeRateHelper::newExchangeDate(Ledger::current(), myTempTmp.AField3, myTempTmp.AField2);

                   myTempTmp.ExchangeRate = exchangeRateHelper.getExchangeRate1()/100;

           }

    myTempTmp.AField4 = purchLine.PurchId;

    myTempTmp.AField5 = vendTable.AccountNum;

           myTempTmp.update();

       }

       ttscommit;

    }

    I have a UIBuilder Class that creates a dialogue box prompting for the Date parameter.

    on the dialogue box there is a "Select" button that can be used to fill in the ranges defined on the query in the AOT.

    This is where my issue is coming in. When i add a value in the AOT --> Queries --> MyQuery --> DataSources --> PurchTable --> Ranges --> PurchId and in the properties panel add a PO number as a value, it filters my report for only that PO (which is correct) YET...when i put the PO number in on the "select" screen on my dialogue box, it doesn't filter the report.

    I hope this explains it a bit better.

    Thanks,

    Adrian

  • venkatesh vadlamani Profile Picture
    3,180 on at

    I dont see that you are using any AOT query or SYSquery in this method.

    If you add a range to report query through dialog, you need to use the dialog instance of the query using this.parmquery().  I dont see this being used.

    Can you tell me where you are using the dialog query instance ???

  • Suggested answer
    dolee Profile Picture
    11,279 on at

    Hi Adrian,

    Let's use Vendor Aging report as an example.

    When a user click Accounts Payable > Reports > Status > Vendor aging, the printing dialog has a "Select" button for user to add ranges to query. It's the same as your requirement.

    Now, let's jump to the code, go to \Classes\VendAgingReportDP\processReport(). The query with the ranges the user adds are stored in parmQuery(). To use it, a QueryRun object is created and assigned the value of parmQuery(). Then the query will be used to fetch records.

    [SysEntryPointAttribute]
    public void processReport()
    {
        QueryRun qr;
        ForwardBackwardPrinting tmpDirection;
        boolean reverseAmountsAndHeadings;
        RecordInsertList tmpTableRecordList = new RecordInsertList(tableNum(VendAgingReportTmp), true, true, true, false, true, vendAgingReportTmp);
    
        contract = this.parmDataContract() as VendAgingReportContract;
    
        qr = new QueryRun(this.parmQuery());
    
        // ...
    }

    In the sample code you shown, it doesn't seem to lookup parmQuery(), so the user added ranges would not  apply.

  • Adriano.85 Profile Picture
    180 on at

    So even though i'm not using the while (queryRun.next()) i still need to have queryRun = new QueryRun(query); ?

    or am I missing the point completely ?

  • dynamics developer Profile Picture
    2 on at

    Hi Adrian,

    you can apply values to AOT query ranges using the following technique

    hasRangesOrFilters = SysQuery::queryHasRangesOrFilters(_query);
    
        if (hasRangesOrFilters)
        {
            qbds = _query.dataSourceTable(tableNum(GeneralJournalEntry));
    
            // Set the range value for the date range.
            range = SysQuery::findOrCreateRange(qbds, fieldNum(GeneralJournalEntry, AccountingDate));
            range.value(SysQuery::range(_fromDate, _toDate));
        }


  • Adriano.85 Profile Picture
    180 on at

    Hi Dominic,

    so if I add  qr = new QueryRun(this.parmQuery()); above my ttsbegin; it should work ?

    Thanks

    Adrian

  • dolee Profile Picture
    11,279 on at

    I dont get your logic. If you just add qr = new QueryRun(this.parmQuery()); and then not using "qr" in anyway, how would that suddenly make your code work?

  • Adriano.85 Profile Picture
    180 on at

    Hi Dominic,

    The logic behind my question was, seeing as I am new to AX dev / reporting, I thought maybe I missed something as trivial as not adding the "qr = new QueryRun(this.parmQuery());" and in turn I did not initialize that the ranges from the dialogue box  get applied...or something like that. Apologies for the ignorance.

    Aside from that - would I need to put the insert_recordset ... select where... section of my code inside a while (queryRun.Next()) ?

    I'm trying to understand how to use the Select part of the dialogue with the insert_recordset.

    Thank you for the patience.

    Thanks,

    Adrian

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans