Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Adding extra data sources and filters to AOT query by code

(0) ShareShare
ReportReport
Posted on by

I have a RunBaseBatch class , I try to apply extra filters on its query by adding data  source to one of its original data sources  and then add range to it  below is my code , the extra dded filter done not have any effect to the list of records retrieved by the query , how can I apply  extra filters by code to AOT query  provided that extra filter is applied on dataource not part of AOT query ?

QueryBuildDataSource qbdshcmWorker = queryRun.query().dataSourceTable(tableNum(HcmWorker));
QueryBuildDataSource qbdsMyTable = qbdshcmWorker.addDataSource(tableNum(MyTable));
qbdsMyTable .joinMode(joinMode::InnerJoin);
qbdsMyTable .relations(true);
QueryBuildRange MyTableRange = qbdsMyTable.addRange( fieldNum(MyTable, Mycategory));
MyTableRange .value(MycategoryValue);

I try to print the query using info(queryRun.query().dataSourceNo(1).toString()); I cannot find extra added data source  MyTable and its added range 

  • maram fraij Profile Picture
    maram fraij on at
    RE: Adding extra data sources and filters to AOT query by code

    By adding qbdsMyTable.fetchMode(QueryFetchMode::One2One) , data source appears and the filter applied correctly .

    Thank you Martin

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: Adding extra data sources and filters to AOT query by code

    You shouldn't depend on QueryBuildDataSource.toString() - that you don't see the datasource there doesn't mean that it isn't used by the query.

    If you want to see the new DS there, try adding qbdsMyTable.fetchMode(QueryFetchMode::One2One).

  • maram fraij Profile Picture
    maram fraij on at
    RE: Adding extra data sources and filters to AOT query by code

    I need just to confirm two points before testing the code in a job :

    1. we can update AOT query by adding extra data sources by code during the execution of the code, right ?

    2. Using info(queryRun.query().dataSourceNo(1).toString());  is correct way to check the effect of the extra added data source and range on the query , right ?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Adding extra data sources and filters to AOT query by code

    Take a look at the "setRangeFromDialog" method that is called from the run method. Perhaps it helps you figure out your code?

    Also, we can assume that perhaps you should test your code (from your first message) in a job, completely separated from this CoC and any standard code. This way you can first perfect your query, and when it's working, inject it in the standard process.

  • maram fraij Profile Picture
    maram fraij on at
    RE: Adding extra data sources and filters to AOT query by code

    I am working on standard class (PayrollIssueWorkerPayProcess) , I  use CoC to do the update on run method  below is the code that I apply

    public void run ()

    {

         this.ApplyExtraFilterToOriginalqueryRun();        

         next Run();

    }

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Adding extra data sources and filters to AOT query by code

    Would it be possible to perhaps see your run method? It would really help in trying to spot the issue, as you can imagine. Thanks!

  • maram fraij Profile Picture
    maram fraij on at
    RE: Adding extra data sources and filters to AOT query by code

    This code is added at the beginning of  run method  before looping over query records. The info message  to get query being executed is called just after the query range value

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Adding extra data sources and filters to AOT query by code

    And where do you call your code? 

  • maram fraij Profile Picture
    maram fraij on at
    RE: Adding extra data sources and filters to AOT query by code

    it is correct , the issue is not in assigning range value ; it is that the new added data source never appears in query being executed

  • tkilmer76 Profile Picture
    tkilmer76 110 on at
    RE: Adding extra data sources and filters to AOT query by code

    How about MyTableRange.value(Mycategory);

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans