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)

Changecompany switch back to current company in the loop

(0) ShareShare
ReportReport
Posted on by

Hi,

In AX2012, when I process the following code I found out the company switch back to the current company in the middle if during the process I click the cursor on AX interface. 

For example, the job is called inside company US,  while working on company UK, I click anywhere on AX interface, the company switch back to US.

Is this a limitation of changecompany function? How can I get this resolved?

 

Thanks.

===my code===

 while select DataArea where !DataArea.isVirtual            

{

                changecompany (DataArea.Id)                

{                 

//actual code..                

}

}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rudi Hansen Profile Picture
    4,075 on at

    I do not understand your question, especially what do you mean by "I click the cursor on AX interface. "

    Normally when you have a job running you can't really press anywhere on AX with out the screen freezing up on you.

    But one general thing you might have forgotten, when you use the changecompany command, any tables you use inside the brackets { } you have to remember to null before using them, so if you are doing something on salesTable the code should look like this.

        while select dataArea where !dataArea.isVirtual
        {
            changecompany (dataArea.Id)
            {
                salesTable = null;
                while select salesTable
                {
                    // Do stuff
                }
            }
        }
    

  • Suggested answer
    raelhefn Profile Picture
    on at

    take a look to this post. it will assist you to find solution :

    community.dynamics.com/.../65659.aspx

    I think you need to reinitialize your objects when select to next company

  • Community Member Profile Picture
    on at

    Thank you for your response.

    I meant 'when I click on AX user interface' in the original post.

    The code inside the changecompany loop is another method and I made sure all the tables are defined inside the method and set to null after they are defined even though it is not necessary by calling a new method.

    When the job is running user can still click on AX interface even though nothing happen, but that triggered the problem.

    I put several check point to verify when the company switch back to current company and each time it happened at different points, which means it is not triggered by the code, instead most likely by user interference.

    Thanks!

  • Community Member Profile Picture
    on at

    Thank you for your reply.

    I followed this post and made sure all the tables are reset before using them. I even got ride of all the infolog and dialog in this method. And I'm using a new method inside the changecompany loop too.

    Thanks.

  • Community Member Profile Picture
    on at

    We have similar processes running on batch job, which had no problem at all.

    Anyone else had the same situation?

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