Pages

Sunday, January 1, 2017

Batch jobs in Dynamics 365

My intention was to test how batch jobs are working in new Dynamics 365.

At first configuration. Configure batch group. Please check mentioned blog post and see if your configuration is correct.

Additional check if Microsoft Dynamics AX Batch Management Service is Running.






Basic code for batch job.

class goBatchTest extends RunBaseBatch
{
    #define.CurrentVersion(1)
    #define.Version1(1)

    public boolean canGoBatchJournal()
    {
        return true;
    }

    public boolean init()
    {
        return true;
    }

    protected void new()
    {
        super();
    }

    public container pack()
    {
        return [#CurrentVersion];
    }

    public void Update()
    {
        CustTable custTable;

        while select firstonly10 custTable
        {
    
            info(strFmt("[%1] %2", custTable.AccountNum, custTable.name()));
        }
    }

    public void run()
    {
        #OCCRetryCount
        if (! this.validate())
            throw error("");

        try
        {
            ttsbegin;

            this.Update();

            ttscommit;
        }
        catch (Exception::Deadlock)
        {
            retry;
        }
        catch (Exception::UpdateConflict)
        {
            if (appl.ttsLevel() == 0)
            {
                if (xSession::currentRetryCount() >= #RetryNum)
                {
                    throw Exception::UpdateConflictNotRecovered;
                }
                else
                {
                    retry;
                }
            }
            else
            {
                throw Exception::UpdateConflict;
            }
        }

    }

    public boolean runsImpersonated()
    {
        return true;
    }

    public boolean unpack(container packedClass)
    {
        Version version = RunBase::getVersion(packedClass);
    ;
        switch (version)
        {
            case #CurrentVersion:
                [version] = packedClass;
                break;
            default:
                return false;
        }

        return true;
    }

    public boolean validate(Object _calledFrom = null)
    {
        if (false)
            return checkFailed("");

        return true;
    }

    server static goBatchTest construct()
    {
        return new goBatchTest();
    }

    static ClassDescription description()
    {
        return "Test batch job";
} static void main(Args args) { goBatchTest goBatchTest; goBatchTest = goBatchTest::construct(); if (goBatchTest.prompt()) goBatchTest.runOperation(); } protected boolean canRunInNewSession() { return false; } }

When you are coding and extending from classes, below screen shows how and what methods you can override.




Next thing is right click on batch class object and select Set as Startup Object. After that Ctrl+F5.

You should see this windows. Configure batch job as usually in older versions of Dynamics AX.


Check results in System Administration. Working as expected.



As I see in this very basic actions, I haven't found no changes to previous versions of Dynamics AX batch jobs. Everything seems to be pretty much the same, at least till that moment.

No comments:

Post a Comment