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)

Empty Returned Value

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

How can I test if there is no returned value when executeQuery method in dataSource is running? there is any way to count the number of returned records?

Code:

 itemQbr = InventTable_ds.query().dataSourceName('InventTable').addRange(fieldnum(InventTable,ItemId)); 
itemQbr.value(queryvalue(X)); if(InventTable_ds.getNext()== null) // { info("not found!"); } else { InventTable_ds.executeQuery(); }


Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi Ennasri Ameni,

    I think you can try to do something like this:

    InventTable_ds.query().dataSourceName('InventTable').addRange(fieldnum(InventTable,ItemId)).value(queryvalue(X));
    
    if (SysQuery::countTotal(InventTable_ds.queryRun()))
    {
        InventTable_ds.executeQuery();
    }
    else 
    {
        info("not found!");  
    }
  • Community Member Profile Picture
    on at

    Hi ievgen Miroshikov,

    Thank you,

    The method countPrim is declared private and may only be called from methods in class SysQuery.

  • Mea_ Profile Picture
    60,284 on at

    Sorry i did not have access to ax :) Please use SysQuery::countTotal() instead

  • Community Member Profile Picture
    on at

    yes i have tested it, but i get the following error: Argument '_queryRun' is incompatible with the required type.

  • Mea_ Profile Picture
    60,284 on at

    again my bad

    if (SysQuery::countTotal(InventTable_ds.queryRun()))

    but if you are doing this when queryRun does not exist yet you probably will have to write

    if (SysQuery::countTotal(new QueryRun(InventTable_ds.query())))

    Also if you have multiply datasources joined to inventTable you may want to use SysQuery::countLoops()

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    If you just want to check whether a record exists or not, you could do this in the datasource executeQuery:

    public void executeQuery()
    {
        super();
        
        info(strFmt('%1', this.cursor() ? true : false));
    }


  • Community Member Profile Picture
    on at

    Hi ievgen Miroshnikov,

    I have tested SysQuery::countTotal and it works fine, but with SysQuery::countLoops(), i have get a SysClientPolymorphicCreateSelector prompted, any suggestion please?

  • Mea_ Profile Picture
    60,284 on at

    Then use countTotal(), in your case it does not really meter. Main difference between them is the way how count is done, but here you need to know if at least 1 records exists so countTotal() could be used without any doubts.

  • Community Member Profile Picture
    on at

    I have tried both  countTotal() and countLoops() and i got a SysClientPolymorphicCreateSelector FORM prompted.. here is my query: I have 2 dataources Inventable and BOM Table in my form:

            qbds1 = InventTable_ds.query().DataSourceTable(tableNum(InventTable));
            qbds2 = qbds1.addDataSource(tableNum(BOM));
            qbds2.relations(true);
    
            quantityFilter = qbds2.addRange(fieldnum(BOM,BOMQty));
            quantityFilter.value(queryvalue(search.text()));
    
            if (SysQuery::countTotal(new QueryRun(InventTable_ds.query())) == 0)
            {
                quantityFilter.value(SysQuery::valueUnlimited());
                info('notfound');
            }


  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi Ennasri Ameni,

    I don't think tat it is connected to this code at all. You can get SysClientPolymorphicCreateSelector  form only when you have table that is part of inheritance hierarchy on the form and data source has property insert if empty = Yes.

    If you will remove this code you should get same form.

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