web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

[AX 2012] Externally Running Batch Jobs

(0) ShareShare
ReportReport
Posted on by 970

Hello,

I'm interested in running batch jobs from C# code I will be writing. I can't seem to "get it" though. First, I looked at the easiest thing for me: web services. There doesn't SEEM to be such a web service (correct me if I'm wrong). After playing around with that for a while, I moved onto the .NET Business Connector. There're a pair of functions in the "Axapta" class called "CallJob." When I saw this, I thought to myself "Nice, I found it." So I go to use it. The input is "jobName." OK, cool. I went looking for a "Job Name."

.... what's this? Batch Jobs don't have a name associated with them? (or, at least, I don't know where to find them)

Using the batch jobs' IDs didn't work either.

I'm kind of running out of options here. It would seem this can be done, but I haven't found an OUNCE of documentation about how to run batch jobs from an external source (my C# code, for example).

Any ideas???????? I'm at a total loss!

Thanks!

 

P.S.> What's this "CallJob" function supposed to actually call, anyway?

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Why don't you just implement your own WCF service calling any AX logic you need? See Using Custom Services.

  • bdzevel Profile Picture
    970 on at

    I really need a more generic, non-environment-specific way of doing this. Is that really the only way?

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    1) There is not such webservice, you would have to write your own.

    2) It can be done through Business Connector, but you have to call actual X++ objects handling these things. I think BatchInfo.doBatch() is a good place to start.

    3) If you mean Axapta.CallJob(), it really call jobs. Job is a special element in AX AOT; it's basically a static method used for small tasks during development or so.

  • bdzevel Profile Picture
    970 on at

    Thanks I'll look into it...

     

    EDIT: Where is this BatchInfo class? My Microsoft.Dynamics.BusinessConnectorNet namespace doesn't contain such a class... (or ANYTHING with "Batch" in the name for that matter)

     

    EDIT2: I'm assuming from the small amount of research I just did that that's an X++ construct.

     

    SO IN OTHER WORDS, you are telling me that there is no way to run an MS Dynamics AX batch job in a generic fashion, correct? (Like, if I input the Batch Job ID and parameters or w/e)

     

    EDIT3: I still feel as though there must be a way to do this.......

  • bdzevel Profile Picture
    970 on at

    Hello again,

    I'm using this code (.NET Business Connector)

              var obj = AX.CallStaticRecordMethod("Batch", "findRecId", 5637144863); //this properly locates my batch job

              var obj2 = AX.CreateAxaptaObject("RunBaseBatch"); // creates an object

              var rv = obj2.Call("parmCurrentBatch", obj); //returns my batch job record, which seems to tell me "it worked"

              var rv2 = obj2.Call("doBatch");

    This doesn't seem to do anything... at least, my batch job doesn't appear in my batch job history.

    What do I call??

    Ugh this is so frustrating.

     

    EDIT: The following code had a similar (non-)effect. I only put it in here 'cause you mentioned "BatchInfo" specifically.

                var obj = AX.CallStaticRecordMethod("Batch", "findRecId", 5637144863);

                var obj2 = AX.CreateAxaptaObject("RunBaseBatch");

                obj2.Call("parmCurrentBatch", obj);

                var obj3 = AX.CreateAxaptaObject("BatchInfo", obj2);

                //var rv = obj2.Call("parmCurrentBatch", obj);

                var rv2 = obj3.Call("doBatch", false);

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Your code can't work, I'm surprised that it doesn't throw any error (because you make an instance of abstract class RunBaseBatch). Why don't you simply look into code how batches work? That's the only way how to really understand what you need to do.

    First example - create an instance of a some batch class (EventJobCUD in this example), than get its batchInfo, set it to run in batch and call doBatch():

    RunBaseBatch batch = new EventJobCUD();
    BatchInfo batchInfo = batch.batchInfo();
    ;
    batchInfo.parmBatchExecute(true);
    batchInfo.doBatch();

    You have to set any parameters required by the batch, that's when the Batch table comes in handy, because it contains packed parameters. Find your batch, build the instance, set parameters and use it as in the first example:

    Batch batch = Batch::findRecId(5637144863);
    RunBaseBatch runBaseBatch.object();
    BatchInfo batchInfo = runBaseBatch.batchInfo();
    ;
    runBaseBatch.unpack(batch.Parameters);
    batchInfo.parmBatchExecute(true);
    batchInfo.doBatch();

    By the way, parm* methods always return the same value as provided in parameter, that's how the design pattern works.

  • bdzevel Profile Picture
    970 on at

    Honestly I was expecting it to throw as well.

    Looks like I have my work cut out.

    Thank you very much.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans