Create sales orders from external database

lloydf
Member Posts: 73
I am relatively new to Navision and am not sure if it is possible to do the following:
I have a web site which takes sales orders. These orders are logged in a sql server database within two tables, OrderHeaders and OrderLines.
Is it possible to do one of the following:
write a script which would import the orders from SQLserver and process the orders through Navision
or
Insert the order data directly into the relevant database tables in Navision.
Any advice would be greatly appreciated
I have a web site which takes sales orders. These orders are logged in a sql server database within two tables, OrderHeaders and OrderLines.
Is it possible to do one of the following:
write a script which would import the orders from SQLserver and process the orders through Navision
or
Insert the order data directly into the relevant database tables in Navision.
Any advice would be greatly appreciated
0
Comments
-
Do not ever create Sales Orders directly into the Navision database. That is a sure way of missing important business logic that runs when users create sales orders in navision.
Other than that there's a few possibilities.
You can look into creating a view in your Navision SQL database into the external database and creating a linked table in navision. You could then write a routine that checks this view and process the data you find in there.
You could also send the sales orders as XML documents into a message queue and have a NAS listen to the queue.0 -
If you don't mind buying objects for these two tables, and they are - or can be migrated - to the Navision SQL database, then you could integrate these tables into Navision as described in the "Viewing SQL tables from Navision" topic and then simply write OnInsert code to these tables to create the orders. The important thing is to do it as an exact mimic of what users do on forms:
CLEAR(SalesHeader); //forget RESET
SalesHeader.VALIDATE("Document Type",SalesHeader."Document Type"::Order);
SalesHeader.INSERT(TRUE); // now you got a No. automatically
SalesHeader.VALIDATE("Sell-to Customer No.", OrderHeader.CustomerNo);
SalesHeader.VALIDATE("Shipment Date", OrderHeader.DueDate);
.
.
.
SalesHeader.MODIFY(TRUE);
If you don't want to buy two tables, it is a little bit more tricky, but a very pretty challenge, if you consider yourself a hacker, you will really enjoy it.
First, install Navision Application Server. There is a quite lame official manual for it, but look around in the downloads sections, there are two helpful downloadable documents about it. One of these documents also tell about using Navision Timer OCX - you will need it. Just search downloads for Application Server or NAS.
Now, NAS works the following way: when an external program runs the EXE file, it receives a parameter provided by you, and then NASHandler function in Codeunit 1 checks this parameter and runs some Navision code once - only once - based on it. If you don't use Commerce Portal, User Portal or Commerce Gateway, simply comment all of this function out by { } braces, because otherwise you will have problems - I was too lazy to investigate why, but no need for this code if you don't use the above-mentioned functionality.
Then, add your code to this function, maybe based on the parameter like on the factory code, this code runs a codeunit you make. The codeunit should use Navision Timer OCX and run in an infinite loop, checking a directory, for example C:\IMPORT in every second looking for files there. For example, header files have a h_ and a GUID name, line files have a l_GUID name.
It loads them by FILE functions, and creates the Sales Order like the code above, and then erases the files.
Then, go to you SQL server, and make triggers to create these files when an order is inserted - write code to create files, maybe with a a shell call to bcp or other means. The file name can be generated be NEWID function, which makes GUIDs.
Why are GUID-s important? Because maybe orders arrive more quickly than 1 second. If you would make a new file with the same name before the previous one is deleted, obviously you would get an error message.
If you don't like the two above solutions, it is also a possibility to create SO-s in SQL, but it is usually not recommended. It is "unsupported" () and you could get strange results because you have to emulate business logic you maybe don't really know. But you can try it. If you try it, you have to manage the following:
- No. Series
- Reservations, if needed
- Item Tracking, if needed
- Unit Price, Line Discount and Invoice Discount Calculation, if needed
- Date calculations, if needed
- Order Tracking, if needed,
- Unit of Measure conversions, if needed
- anything else I forgot (perhaps not much)
so it is a hard task with many obstacles. I suggest to choose the first or second possibility and resort to it only if you are prepared for heavy swearing
Do It Yourself is they key. Standard code might work - your code surely works.0 -
You don't need the Navision Timer OCS in this case, you can also use the SLEEP-function.
You can also create a NAS-setup-record with the value for the SLEEP-function. And also put a boolean in it when the NAS has to stop.
And some NAS code like this:
recNASSetup.get();
if recNASSetup."Stop NAS" then
EXIT;
WHILE TRUE DO BEGIN
ProcessWhatYouHaveToProcess();
recNASSetup.get();
if recNASSetup."Stop NAS" then
EXIT;
SLEEP(recNASSetup.SleepInMilliseconds);
END;
For the rest I agree with the suggestion of Shenpen to use first or second possibility.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions