I have a situation with test extension which I am building.
Let say I have a two companies in Business Central. I want to perform test a procedure which will include both companies. On first company I will generate some Sales Orders and I will generate Purch. Orders and I will send them to another company to process until the end.
I know that CHANGECOMPANY method exists for records but this does not help.
How can I in AL code declare or call some method to change company and then on some step i call a method which will change company to another, again.
Anyone did something similar? I heard about sessioninfo variable but honestly I didn't find anything useful for my case. Please help if someone have any idea.
Thanks in advance guys!
CHANGECOMPANY does change the company of the current record-variable only.
E.g. when you use SalesHeader.CHANGECOMPANY('whatever company it is') all other tables (e.g. Customers) would remain in the original company.
To really work completely in a company, you have to start a new session using StartSession: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-startsession-method
You must set a codeunit as parameter which will be executed in the new company.E.g. STARTSESSION(SessionId, CODEUNIT::"Create Sales Order", 'whatever company it is', OptionalRecord);
STARTSESSION(SessionId, CODEUNIT::"Create Sales Order", 'whatever company it is', OptionalRecord);
Hi Hannes, thank you for your reply.
I tired to work with sessions but when I start a session in test function i get error:
"Sessions cannot be started in tests that are run by a TestRunner that has TestIsolation set to Test or Codeunit."
The solution I see in my case is to refactor the test scenario to smaller pieces to avoid sessions. Changing the Test Isolation doesn't make sense.
Yes. Maybe think per company only.
That means, your test creates data in your current company only.
When testing the functions in the other company, you create data accordingly to feed the test functions.
Yes¸, test per company will be the only option.
Thank you Hannes for your thoughts! I appreciate it!
Business Applications communities