How to get next "Document No." in another company

Hi I import some data into a General Journal from a CSV file in ‘CompanyA’. No problem. Now some of the lines I need to insert into a General Journal in another company ‘CompanyB’, but how do I get the next available “Document No.” in CompanyB ? I know I can use ChangeCompany to insert a record in CompanyB, and use codeunit 396 NoSeriesManagement to get next “Document No.” in current company, but I dont know how to get the next “Document No.” from another company ! I have tried, but keep getting the “Document No.” from CompanyA. Any suggestions or codesnippets are welcome [:D] /Lars

On the ge. journal line, document no. is per batch (if you defined the no. series for that batch). You can use the changecompany for the No. Series table. look for the no. series for that batch, then calcfield on “Last No. Used” and then use INCSTR to this Last no. used to get the document no.

quote:


Originally posted by Streg
…I import some data into a General Journal from a CSV file in ‘CompanyA’. No problem. Now some of the lines I need to insert into a General Journal in another company ‘CompanyB’, but how do I get the next available “Document No.” in CompanyB ?..


Which Company do you want the General Journal Lines? A or B. If, as I read, you want some records in A and some in B, you will find the easiest is to run the import twice…Once for each Company. If you are really looking for the Next Document No. only, then Naveen’s method is the best. If you are looking to actually update that number in Company B, but use it in company A [?] then you have some more work.

quote:


Originally posted by naveenjain
On the ge. journal line, document no. is per batch (if you defined the no. series for that batch). You can use the changecompany for the No. Series table. look for the no. series for that batch, then calcfield on “Last No. Used” and then use INCSTR to this Last no. used to get the document no.


Sorry, but You can’t. The formula for the field that You want to do a calcfield for is based on another table. That table is not affected by the CALCFIELD on the first table. You have to build You own code to manipulate data in another company. As soon as a flowfield or a trigger references another table that reference will be made to Your current company. I wish indeed it would be otherwise.

Thanks to all of you Since there was no easy solution, I have decided to simply check for missing “Document No.” when I start the General Journal, and insert the missing ones. /Lars

quote:


I know I can use ChangeCompany to insert a record in CompanyB, and use codeunit 396 NoSeriesManagement to get next “Document No.” in current company, but I dont know how to get the next “Document No.” from another company !


The problem with ChangeCompany is that you have to change for each record / variable you use. In your case you should create a new procedure in the NoSeriesManagement (CU 396) to change the company. In this procedure you must ChangeCompany for all internal variables. Note: Sometimes it’s also neccessary to add code in other procedures in order to ChangeCompany for local variables. And if you are real lucky the codeunit calls a new codeunit where you need to use the same trick. But the point is: It is possible to get the Document No. from another Company !