Good afternoon,
I'll give it a try whilst I am having troubles finding simple tutorials or look-a-like projects.
Our company is using: NAV 2009 R2
I have limited access (only object designer) due to license.
I am trying to write code behind a report.
I would like that once the report is ran, it mirrors delivery weeks (Company A master) between two companies.
The No.'s in sales headers are matching.
Company A
Sales Header No. 00001 - delivery week 30
Sales Header No. 00002 - delivery week 28
Company B
Sales Header No. 00001 - delivery week 24 (should be updated by report to 30)
Sales Header No. 00002 - delivery week 25 (should be updated by report to 28)
I've checked CHANGECOMPANY, but mostly it is people warning of usage.
Can someone give me a little push in the right direction?
0
Answers
CHANGECOMPANY can be dangerous if used in wrong ways, but if you know what you're doing, and it's used under a controlled scenario, I don't see issues with using it.
What is the use case here? Is Company B a copy of Company A? How can you guarantee that Sales Orders in Company B are the same as the ones in Company A?
These are initial questions that come to my mind when I take a look at your initial design.
D365 Business Central Solutions Architect
BC AL/NAV C/AL Developer
BC Repositories.com
Thanks for your reply.
Company B is a copy of Company A (main)
I can guarantee that the sales order is always the same.
Our system mirrors the sales orders from Company A into B.
The use case is:
As shared in my first message, it happens that a delivery week is changed in company A. Unfortunately there is no working functionality/code that updates also the delivery week in Company B. This is what I would like to achieve.
My first thought would be to run a report with this code behind it, let say in a job queue at the end of the day or for example manually ran for specific orders.
Company A
Sales Header No. 00001 - delivery week 30
Sales Header No. 00002 - delivery week 28
Company B
Sales Header No. 00001 - delivery week 24 (should be updated by report to 30)
Sales Header No. 00002 - delivery week 25 (should be updated by report to 28)
You need to know that CHANGECOMPANY only changes the source for this record's tabledata. If you validate any field, the validation code will validate its tablerelation against the current company's data, and any record variable that is used in the validation code references the current company's data.
Therefore you should not alter anything that requires validation in the record you called CHANGECOMPANY on, unless you know it is save.
Everything is ok, if you read data. so, for your business case, consider pulling data from company B, rather than pushing it from company A.
In your case, I guess the shipment week is somehow linked to the "Shipment Date". This again will be synchronized from header to lines. Therefor it is unlikely you will be able to do this from company A.
Other possible solutions:
- create a web service and call the service from company A in company B
- if STARTSESSION is available in 2009, you can use it to run a background session from company A in company B
- use the Job Queue in Company B to do the work. This job may scan documents in company A using CHANGECOMPANY, or use a staging table which you populate from company A with or without CHANGECOMPANY to company B.
I did not understand what you meant by How does this limit you? Did you mean "only report designer"?