Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

CHANGECOMPANY command and triggers execution

(1) ShareShare
ReportReport
Posted on by

Hi, in the help I read:

"Even if you run the CHANGECOMPANY function, triggers still run in the current company, not in the company that you specified in the CHANGECOMPANY function."

and

Rec.CHANGECOMPANY('B');
Rec.FINDFIRST;
Rec.MODIFY(TRUE);

If you run the code in this example from Company A, it will modify Rec in Company B, but it will run the OnModify trigger in Company A.

This looks wrong.

So if write a code like

  ExtTextHeader.CHANGECOMPANY("B");
  ExtTextHeader.SETRANGE("Table Name",ExtTextHeader."Table Name"::"G/L Account");
  ExtTextHeader.SETRANGE("No.","No.");

  ExtTextHeader.DELETEALL(TRUE);

Since in ondelete trigger of ExtendedText Header table there is the following code


OnDelete()
ExtTextLine.SETRANGE("Table Name","Table Name");
ExtTextLine.SETRANGE("No.","No.");
ExtTextLine.SETRANGE("Language Code","Language Code");
ExtTextLine.SETRANGE("Text No.","Text No.");
ExtTextLine.DELETEALL(TRUE);

Should I expect that headers are deleted in Company B and lines (if any with same No.) are deleted in Company A?

*This post is locked for comments

  • Rashed Profile Picture
    Rashed 3,765 on at
    RE: CHANGECOMPANY command and triggers execution

    It does not use additional session.  You can have unlimited background sessions.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CHANGECOMPANY command and triggers execution

    Hi iumy. I have in fact on my hands exactly tthe same problem. I use 16 companies and need to create for them Customers, Vendors, etc ... the same records in each one. I understand and found exactly what you lool. NAV modify the records from the Company where records are created, but not from the other companies. Do you suggest or look any solution anywhere. Because for big companies and use intercompany process this is critical; without this any solution is .. shit. Tks and regards.

  • iumy Profile Picture
    iumy on at
    RE: CHANGECOMPANY command and triggers execution

    Thanks. it would save some coding, especially if there are many triggers called in chain but it would use an additional session

  • Rashed Profile Picture
    Rashed 3,765 on at
    RE: CHANGECOMPANY command and triggers execution

    I suggest to use STARTSESSION in NAV 2013  to run a codeunit in another company to modify the any records. 

  • iumy Profile Picture
    iumy on at
    RE: CHANGECOMPANY command and triggers execution

    Thanks for your reply. I already tested and know the answer but I believe this Nav behaviour is very risky.

    It requires a lot of coding while one of the big advantages in Nav is to let the triggers do their job. I hope Nav team will change this.

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 44,656 on at
    RE: CHANGECOMPANY command and triggers execution

    In your example yes it will delete lines from Company A.

    When you use CHANGECOMPANY function do not use execute trigger function rather write the your own code which is in that trigger to execute in your function.

    Example:  Use ChangeCompany on ExtTextHeader, ExtTextLine and apply filters on both tables then execute DELETEALL

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,387 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans