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 :
Microsoft Dynamics AX (Archived)

How to run a Batch job for all Companies?

(0) ShareShare
ReportReport
Posted on by 530

Hi, I'm creating a customization to import xml files and insert the values in LedgerJournalTable and LedgerJournalTrans. For this task I have to create a batch job that will from time to time (highly frequent) do the process automatically. 
Now, I have two problems:-
1. Since, there are 200+ legal entities, do I have to create a job to be executed on each legal entity? What are the consequences (performance issues) ?
2. How to control at the time of import as to this data will be inserted in which legal entity?

Note: The XML file that I am importing has the <company> </company> tag to inform me as to in which company this data should be inserted. I don't have the know-how as to how to use this information while inserting data.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,570 Most Valuable Professional on at
    RE: How to run a Batch job for all Companies?

    You can look at Cross-Company X++ Code Basics on MSDN.

    Nevertheless note that Application Integration Framework already supports these things and it even already contains a document service for general ledger journals (LedgerGeneralJournalService). Using that would make better sense to me that developing something similar again.

  • Verified answer
    syed baber Profile Picture
    11,633 on at
    RE: How to run a Batch job for all Companies?

    Hi Osama,

    You can use the changeCompany statement to change the current company to the company you retrieve from your import file and then whatever records you are going to create would be inserted in that company. So, basically you need to traverse through the records of your import file and inside the while loop, you change the company based on the company in the import file and then creates the record.

    Recently, I did the same thing by importing the records from csv file to create vendor invoice journal and register in AX.

    Please let me know if you have further queries.

    Thanks,

    Baber.

  • Osama Anjum Profile Picture
    530 on at
    RE: How to run a Batch job for all Companies?

    Since, I've created code for both (import and export) and the only thing that I need is creating batch jobs, is there any work around other than using AIF Document Service.

    There is not much information concerning my issue with respect to Cross-Company available.

  • Osama Anjum Profile Picture
    530 on at
    RE: How to run a Batch job for all Companies?

    Thanks Baber, looks like a more likely solution. Please confirm one thing here- the batch job can run on any company and during the execution it will change the company based on the <company> tag?

    Also it would be generous of you if you could specify where to look for to get info on changing company.

  • syed baber Profile Picture
    11,633 on at
    RE: How to run a Batch job for all Companies?

    Hi Osama,

    I am not sure if BatchJob table in AX 2009 is global. In AX 2012, it is global. Still, with changeCompany keyword, you can create records in any company based on the company values coming from your import file.

    Thanks,

    Baber.

  • Verified answer
    Martin Dráb Profile Picture
    236,570 Most Valuable Professional on at
    RE: How to run a Batch job for all Companies?

    You'll read the value of Company and pass it as a parameter to changeCompany(). Please see examples in the documentation that I linked above.

  • Verified answer
    Jonathan  Halland Profile Picture
    11,310 on at
    RE: How to run a Batch job for all Companies?

    That is correct Osama. The batch job can run under any company. Martin already provided you a link regarding the multi-company functionality.  msdn.microsoft.com/.../cc518738%28v=ax.50%29.aspx

    Depending on what exactly you need to do, you may either need to iterate through the list of legal entities you have and use the changeCompany command to change into that context, or do a cross_company select statement on a table and then switch to the correct company per record to do your processing.

    e.g.

    while select crossCompany purchTable....

    {

       changeCompany(purchTable.DataAreaId)

    {

    }

    }

  • Verified answer
    syed baber Profile Picture
    11,633 on at
    RE: How to run a Batch job for all Companies?

    Hi Osama,

    As long as your batch job has batch group assigned to it and that batch group has AOS assigned, then that batch job will run based on the recurrence defined on the batch job irrespective of any legal entity. To change the company, you just need to write changeCompany('CompanyId"). Take a look at below blog post for more information of how to use this:

    community.dynamics.com/.../how-to-change-company-by-the-x-code-in-ax-2009

    Please let me know if you have further queries.

    Thanks,

    Baber.

  • Sheikh Sohail Profile Picture
    6,125 on at
    RE: How to run a Batch job for all Companies?

    You can use Cross-Company in you query to get all Entity data and can perform your goal.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans