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)

How to create Batch Job in Microsoft Dynamics AX 2012 R3?

(0) ShareShare
ReportReport
Posted on by 3,805

Hi all..

Please help me.

Example :

i have a table with name Table_A and field (ID, Name, Flag).

And i have second table with name Table_B and field (ID, Name).

i want, automatic insert record from Table_A to Table_B every 1 hours "If record in Table_A with flag 'Yes'".

i try create batch Job, but not work.

Please help.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Data duplication is not a good idea, why do you need a copy of values?

    Also I do not think you are approaching your problem correctly, maybe explaining your situation better and telling the business scenario would be helpful to understand.

    Anyways, the correct solution if you still want the duplication would probably not be with a batch job, but whenever you insert a new record, or update an existing one where the flag is set, create the record immediately in your other table if it does not exist yet already.

    If you insist on using a batch, then you need to create a custom Entity for your tables, then you could map your source and target tables' fields in the Data Import Export Frameowrk, and finally schedule a batch job which moves the data based on your query criteria.

  • fajar Profile Picture
    3,805 on at

    Thanks Vilmos,

    i just try for Create Batch Job with simple case.

    Actually, i have another case not like this case.

    But, my batch Job not work.

  • Vilmos Kintera Profile Picture
    46,149 on at

    Can you please answer my request and provide additional details?

  • fajar Profile Picture
    3,805 on at

    Thanks Crispin..

    this my code.

    class RunBaseDemo extends RunBaseBatch
    {
    }

    client server static ClassDescription description()
    {
        return "Test Batch Job";
    }

    public void run()
    {
        PIL_RunBaseDemo         _baseDemo;  //this second table
        PIL_DepositoMaster      _depositoMaster; //this first table

        ttsbegin;
        try
        {
            while select _depositoMaster
            {
                if(_depositoMaster.PIL_Started == NoYes::Yes) //flag 'Yes'
                {
                    _baseDemo.clear();
                    _baseDemo.PIL_DepositoID = _depositoMaster.PIL_DepositoID;
                    _baseDemo.insert();
                }
            }

            ttsCommit;
        }
        catch
        {
            error("Process failed");
        }
    }

    static void main(Args _args)
    {
        RunBaseDemo objClass = new RunBaseDemo();

        if (objClass.prompt())
        {
           objClass.run();
        }
    }

    And then i open this class. i set 'Recurrence' every 2 minutes for testing.

    1207.batch.jpg

    i follow this link https://www.dynamics101.com/runbase-framework-microsoft-dynamics-ax-2012/

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    First of all the entire TTS block must be inside your try-catch, currently you do a ttsBegin outside, which is incorrect.

    Secondly, why do you put an if statement on checking the field content, when it could be put in a query criteria, so you do not have to loop through all records?

    Also you should never ever prefix internal variables with the underscore, since that is only reserved for the method's parameters, to indicate that the variable comes from an external call.

    You should do such buffer operations in a single call anyway, because while select is a slower row-by-row based operation.

    Try something like this:

    [View:https://msdn.microsoft.com/en-us/library/aa635694.aspx:750:50]

    insert_recordset baseDemo(PIL_DepositoId)
       select PIL_DepositoId from depositoMaster
           where depositoMaster.PIL_Started == NoYes::Yes
       notexists join baseDemoNotexists // Declare this new variable!
           where baseDemoNotexists.PIL_DepositoId == depositoMaster.PIL_DepositoId;


  • fajar Profile Picture
    3,805 on at

    Thanks Crispin, i will try.

  • fajar Profile Picture
    3,805 on at

    Thanks Vilmos,

    i will try your code for insert my table.

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