web
You’re offline. This is a read only version of the page.
close
Skip to main content
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 

I have the same question (0)
  • tkilmer76 Profile Picture
    110 on at
    RE: Adding extra data sources and filters to AOT query by code

    In your last line of your code, should it be MyTableRange.value(Mycategory.value());

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

    I do not add the whole code ,Mycategory is a variable of type string

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

    How about MyTableRange.value(Mycategory);

  • maram fraij Profile Picture
    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

  • nmaenpaa Profile Picture
    101,160 Moderator 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
    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
    101,160 Moderator 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
    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();

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator 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
    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 ?

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,167

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 867 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 617 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans