Posts Tagged ‘runbasebatch’

original msdn: http://msdn.microsoft.com/en-us/library/cc636647.aspx

In this procedure, you will extend the RunBaseBatch class. Objects of type RunBaseBatch implement all the methods that the system needs in order to run the object as a batch job. You will extend RunBaseBatchto override the run method. The run method contains the logic that handles the particular processing need that you are solving.

To extend RunBaseBatch

  1. Press Ctrl+D to open the Application Object Tree (AOT) in a development workspace.
  2. Right-click the Classes node, and then select New Class.
  3. Expand the node for your new class. Rename it Batch4DemoClass.
  4. Right-click the classDeclaration node under Batch4DemoClass, and then click View Code.
  5. In the code Editor window, after Batch4DemoClass, add extends RunBaseBatch. Save the change.
  6. In the AOT right-click the Batch4DemoClass node, select Override method, and then select the runmethod. Edit the run method to match the code shown in the following example.
  7. Override the methods pack and unpack. Edit them to match the code shown in the following example.
    NoteNote
    For this example, do not yet override the runsImpersonated method. The base method always returns true. true means the batch must run under the authority of the person who scheduled the batch, and that no client session is involved.
    class Batch4DemoClass extends RunBaseBatch
    {
        public void run()
        {
            // The purpose of your job.
            info(strFmt("Hello from Batch4DemoClass .run at %1"
                ,DateTimeUtil ::toStr(
                    DateTimeUtil ::utcNow())
                ));
        }
        public container pack()
        {
            return conNull();
        }
        public boolean unpack(container packedClass)
        {
            return true;
        }
    }

In this procedure, you will write an X++ job that can be run to schedule an occurrence of your batch. Then you will run the job.

To schedule your batch job

  1. In the AOT, right-click the Jobs node, and then select New Job.
  2. In the Editor window, enter the X++ code shown in the following example, and then save the changes.
  3. In the Editor window, press F7 to compile your job, and then press F5 to run your job.
    NoteNote
    The result of your job is that your batch is scheduled to run.
    static void Job_ScheduleBatch2(Args _args)
    {
        BatchHeader batHeader;
        BatchInfo batInfo;
        RunBaseBatch rbbTask;
        str sParmCaption = "My Demonstration (b351)";
        ;
        rbbTask = new Batch4DemoClass();
        batInfo = rbbTask .batchInfo();
        batInfo .parmCaption(sParmCaption);
        batInfo .parmGroupId(""); // The "Empty batch group".
        batHeader = BatchHeader ::construct();
        batHeader .addTask(rbbTask);
        batHeader .save();
        info(strFmt("'%1' batch has been scheduled.", sParmCaption));
    }
  4. Click the Build menu, and then click Generate Incremental CIL.
    This CIL build is necessary because batch jobs that run on the AOS can run only in .NET Framework managed mode.