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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Change query range runtime

(0) ShareShare
ReportReport
Posted on by 453

hi 

I have a AOT query with 1 datasource. I want to change the query range if projid='' and serviceId !''.

In the datasource init() I have this code, but I dont get the required result.

public void init()
{
    QueryBuildDataSource        qbds;    
    QueryRun                    qr;
    
    
    super();
    
    qbds = this.query().dataSourceName('ServiceInvoiceLine_2');
    qr  = new QueryRun(this.query());
    
    while(qr.next())
    {      
        if(ServiceInvoiceLine_2.Projid != '' && ServiceInvoiceLine_2.ServiceOrderid == '')
        {
            qbdsTimeLine.addRange(fieldNum(ServiceInvoiceLine, ServiceOrderid)).value('!""');
            qbdsTimeLine.addRange(fieldNum(ServiceInvoiceLine, Projid)).value("");
            qbdsTimeLine.addRange(fieldNum(ServiceInvoiceLine, jobid)).value('!=""');
        }
    }
}


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,069 Most Valuable Professional on at

    You mentioned a data source, so I'll assume it's init() method of a form datasource. Please confirm whether it's the case and don't forget to mention such crucial things next time.

    Your code looks very strange; I suspect you don't understand what it does, so let me explain it to you.

    You take the datasource query, fetch all records and if the record currently loaded in the form (not the ones you get from the query) has a non-empty ProjId and and empty ServiceOrderId, you add three ranges.

    Therefore is the query return 500 records, you add 1500 (500*3) ranges. That's not very useful.

    Also, whether the ranges will be added or not depends on which record is currently selected. It doesn't depend in any way on records returned by the query. You fetch all records from database but you ignore them completely. If it should depend only on the active record, you can throw away all the code executing the query.

    I think we shouldn't spend more time with your current code. You should rather tell us what exactly you're trying to achieve and we'll help you design something better.

  • Suggested answer
    Community Member Profile Picture
    on at

    Use this qbrCustRef.value(SysQuery::valueNotEmptyString());

  • nmaenpaa Profile Picture
    101,166 Moderator on at

    What is "qdbsTimeLine"? Where is it initialized?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans