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

How we call and run a RunBaseBatch class in code

(0) ShareShare
ReportReport
Posted on by

Hi all,

How we call and run a RunBaseBatch class in code ? Does it mean also the batch job will be run in background ? 

If that RunBaseBatch has a DialogForm which support user input first, then are we able to give the input / parameter in that code when we call it as well ?

Any sample of how we doing this ?

Thanks,

I have the same question (0)
  • Suggested answer
    mhdshb1 Profile Picture
    1,250 on at
  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    you can use below code:

    BatchHeader           batchHeader;
    BatchInfo             localBatchInfo;
    CustumBatch updateBatch = new CustumBatch();
    SysRecurrenceData     sysRecurrenceData = SysRecurrence::defaultRecurrence();
    sysRecurrenceData = SysRecurrence::setRecurrenceEndAfter(sysRecurrenceData, 1);
    
    localBatchInfo = updateBatch.batchinfo();
    batchHeader = batchHeader::construct();
    batchHeader.addTask(updateBatch);
    batchHeader.parmRecurrenceData(sysRecurrenceData);
    batchHeader.save();
    Info("Batch job created");

    when you are creating the object of your runbase batch, you can set the values for parameters as needed.

  • Community Member Profile Picture
    on at

    No, it is not "how to create", it is "how to call / run" and how we give the parameters as well while we call it, because they won't be any user interaction. How to give what supposed to be asked from Dialogfield, in that code.

    Just for additional, this code calling the batch is also a Batch job (created with SysOperation Framework), but my  point is how we call other batch job (which is created using RunBaseBatch).

    Thanks

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi WWwong,

    RunBaseBatch framework just implements features to run a job in batch and build on top of RunBase. You can still run it without batch.

    Let's assume you have class MyClass inherited from RunBaseBatch, in this case, you can run execution in another class with the next example:

    MyClass myClass = new MyClass(); // Or there can be construct method or any static method that instantate class object with parameter
    
    //Initialize some variables used for class processing
    myClass.parmSomething('MyValue);
    myClass.run();

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    Code which I shared will create the batch job for execution i.e. call/run.  you can play with SysRecurrenceData for setting recurrence. the variable of the actual batch job is created. you can set up all the parameters after the initialization of the class variable.

  • Community Member Profile Picture
    on at

    Hi Thanks,

    Honestly, it looks quite "advance" for me. I'm using the one from Sergei, it is much simpler.

    Anyway thanks for the help.

  • Community Member Profile Picture
    on at

    Hi Sergei,

    One more thing though, what's different between using .Run() and .runOperation(). Not a stopper only looking at BP warning, it suggest me using runOperation()

    Thanks.

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi WWwong,

    Yes, you are correct, to avoid BP warning you need to call runOperation or runOperationNow instead. If I understood correctly it's a part of SysOperationSandbox framework and depends on the result of method canRunInNewSession and kind of session (GUI or non-GUI), RunOperation method will execute run method synchronously or in async mode and show you "Waiting "progress" dialog".

  • vinitgoyal2005 Profile Picture
    6,332 on at

    Hi,

    No problem, Sergei's code is for executing the code of RunBaseBatch class synchronously, just like any other class. My code is to run it in batch mode so user doesnt have to wait for it to finish.  

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 663

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 337 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans