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

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)
  • vinitgoyal2005 Profile Picture
    6,332 on at
    RE: How we call and run a RunBaseBatch class in code

    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.  

  • Sergei Minozhenko Profile Picture
    23,093 on at
    RE: How we call and run a RunBaseBatch class in code

    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".

  • Community Member Profile Picture
    on at
    RE: How we call and run a RunBaseBatch class in code

    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.

  • Community Member Profile Picture
    on at
    RE: How we call and run a RunBaseBatch class in code

    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.

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at
    RE: How we call and run a RunBaseBatch class in code

    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.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at
    RE: How we call and run a RunBaseBatch class in code

    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();

  • Community Member Profile Picture
    on at
    RE: How we call and run a RunBaseBatch class in code

    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

  • Suggested answer
    vinitgoyal2005 Profile Picture
    6,332 on at
    RE: How we call and run a RunBaseBatch class in code

    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.

  • Suggested answer
    mhdshb1 Profile Picture
    1,250 on at
    RE: How we call and run a RunBaseBatch class in code

    Hi,

    You can find plenty of samples in the web.

    Check these samples 

    https://dynamicsvn.wordpress.com/2018/10/19/how-to-create-a-simple-dialog-form-using-x-code-and-extending-runbasebatch-class/

    http://www.atomicax.com/content/create-batch-executable-class

    Regards,

    M

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 789 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 497 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans