I have designed a xml port through which i import sales orders into Navision.
How can i increment the Line no field in Navision automatically.
I dont want to hardcode the values for the lines that i have
While inserting the lines NAV automatically has to increment the Line no
CAn anyone pls help.
raghu
0
Comments
You can do that with a variable or you can try to find the last line in your document and add a number to that. Also try doing an INSERT(TRUE) so that you call all the code that's supposed to be executed when you insert into that table.
My Blog - nav.education
Before importing:
Find the Last Line if the imported Order exist and save this Line No. in a variable (Like NextLineNo)
If there is no Line No. set NextLineNo to 10000. If there is one NextLineNo := "Line No." + 10000;
During the import you can increment the variable NextLineNo with NextLineNo += 10000;
This uses a buffer table and a codeunit process converts these records to Sales Orders later.
There are reasons for this approach one being the code for the line number is not on the Insert Trigger of the 'Sales Line table', so the code has been added on the buffer table, the system also needs good data like the Type, 'No.' and Quantity etc: to be properly tested and validated.
When these are validated the 'Sales Line' code gets the Sales Header which will not exist during the xml Import, so you may need to re-think the process.
If you choose not to create a buffer table then to answer your question:
Create a Global Variable LastLineNo
Then code on SalesHeader - Import - OnInsert
LastLineNo := 0;
Then code on SalesLine - Import - OnInsert
LastLineNo := LastLineNo + 10000;
SalesLine."Line No." := LastLineNo;
I would use a buffer table and import the xml into this, then use a codeunit to test the data, marking any bad records and create the good Orders, to do this copy and modify the xml port and buffer tables that already exists into the custom area as the clients own.
David
Mobile: +44(0)7854 842801
Email: david.cox@adeptris.com
Twitter: https://twitter.com/Adeptris
Website: http://www.adeptris.com