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 :
Finance | Project Operations, Human Resources, ...
Answered

Batch job with two Queries

(3) ShareShare
ReportReport
Posted on by 160
Hi All,
 
I'm struggling with this requirement I got. This is a simplified version of what I need to do:
 
Button: When the user clicks this button, this should happen:

First of all, the job should (preferably mandatory) run in Batch. 

I have 2 Simple Queries in the AOT. The user should be able to add filters etc. to both Queries.

Next, the Batch job should run, execute these two Queries and save the results to a table.

For this scenario, assume the first simple Query to contain the custTable. The second one contains the vendTable.

After the user modified the filters on the Batch Job Dialog, the batch job should export the data from these two Queries to the table 'TotalTable', Holding the Customer/Vendor Account and the Customer/Vendor Name
 
 
Normally I could use something like the "Records to include" on the Batch Dialog, but as I have  two Queries I do not really have a clue on how to get  this to work. Is this possible ?
 
Or should I create a normal form or class, giving the user the option to add filters etc. to the Query and then pass these Queries to a class that creates a Batch job with these two Queries ?
 
Any thoughts or someone that might have encountered a similar requirement before ?
 
FYI: I will be away until Wednesday, so I cannot respond before then.
 
Thanks !
 
Gerard
 
Categories:
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,734 Most Valuable Professional on at
    The batch frameworks don't support it, but I'm sure a solution can be found. I don't really have a solution on hand, but I have at least some ideas to consider.
    1. Create a query with two root data sources. I'm not really sure what would happen; it's likely just a first step of some research. But if it succeeds, it may be the simplest solution. I would first check if you can set the filters and the GUI is acceptable for you. If so, we can then talk about how to run the queries.
    2. Check out if you can't reuse the standard logic to add data for an additional query. I'm not sure how feasible it is - it doesn't look impossible to me, but it may be more complicated then suitable for you. The key class is RunBaseDialogModify. For example, the range button is added in initQuery() and values of ranges/filters added in updateQuery(). You'd need to create your own methods similar to these, because you can't inject a second query there. But you'd be able to reuse other methods, such as addRangeAndFilterToDialog().
    3. Add two buttons to the dialog to open the query setup dialog (QueryRun.prompt()), instead of using the default logic that allows you to select ranges of a single query.
    4. You can also use your own modeled form instead of the default dialog and handle the logic there. It'll be beneficial if doing it on your own seems easier than dealing with the standard framework.
  • Gerard Verbruggen Profile Picture
    160 on at
    Hi Martin,
     
    Sorry for the delayed response. I was not available for a couple of days, As always: your response is much appreciated !
     
    I will go for options 3/4 as I as this seem to be the most feasible. When I get it to work, I will post what I did here. This might take a couple of weeks as I have some other projects I'm working on as well.
     
    Cheers,
    Gerard
  • Gerard Verbruggen Profile Picture
    160 on at
    Hi All,
     
    After investigating the options I went for the, in my opinion, easiest solution:
     
    I created a form with two buttons and some other text fields with user input I want to use in the Batch. Each button shows a different Query form and the user can add the desired filters. Furthermore I created a SysOperationServiceController, DataContract and Service class. 
    When the user hits the OK button on the form, the Queries and text fields are passed to the dataContract like this:
     
    myController controller = myController::construct();
    myDataContract dataContract;
    SysOperationStartResult sysOperationStartResult;
    
    controller.parmLoadFromSysLastValue(false);
     
    dataContract = controller.getDataContractObject();
         
    //Have the code executed as a Batch job
    controller.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
    BatchInfo batchInfo = controller.batchInfo();
    batchInfo.parmCaption("My Description");
    
    dataContract.parmPackedInvoiceQuery(packedInvoiceQuery);
    dataContract.parmPackedGLQuery(packedGLQuery);
    dataContract.parmDescription(Description.text());
    dataContract.parmInvoiceFilter(InvoiceQuery.text());
    dataContract.parmGLFilter(GLQuery.text());
             
    controller.parmShowDialog(false);
     
    sysOperationStartResult = controller.startOperation();
    
    element.close();
     
    Works like a charm.
     
    Cheers,
    Gerard

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 577 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 309

#3
Diego Mancassola Profile Picture

Diego Mancassola 259

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans