For loop across all available companies?

送分小仙女□ 提交于 2019-12-10 19:13:07

问题


I need to create a job with a for loop (I think) that goes through all available companies and checks for a specific value. I'm just not familiar with how I would get it to select each individual company.

Does anyone know the syntax for that?


回答1:


The functionality you're looking for is called "Cross Company" data access. MSDN has a great bit of code samples here:

X++ code: http://msdn.microsoft.com/en-us/library/cc518738.aspx

Main article: http://msdn.microsoft.com/en-us/library/cc634544.aspx




回答2:


I use the following technique in a job:

static void CountIt(Args _args)
{
    DataArea  DataArea;

    void doIt()
    {;
        info(int2str((select Count(RecId) from CustTable).RecId));
    }

    setPrefix("Counting");
    while select DataArea where !DataArea.isVirtual
    {
        print(DataArea.Id);
        setPrefix(DataArea.Id);
        changecompany (DataArea.Id)
        {
            doIt();
        }
    }
}



回答3:


Please bear in mind to reset your table variables in the changecompany scope, otherwise you will get strange or no result at all. A colleague was to do a task as yours and he got absolutely no results for the code inside the changecompany scope. I googled and found this blogpost: http://dynamics-ax-live.blogspot.se/2011/10/what-not-to-forget-when-using.html



来源:https://stackoverflow.com/questions/11890348/for-loop-across-all-available-companies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!