Hi Guys,
I’ve asked a similar question before but have to be 100% confident before I commit to it as it’s the basis of an entire project.
In principal it’s very simple, I just wish to add to THIS list from an external source.
I know the information is in the [Purchase Header] table (document type 2).
I don’t want the user to have to perform any action from within the RTC, (file > import etc …) all the work is done outside the Dynamics NAV environment
I’m concerned of the implications of business logic simply INSERTing into the table, so with a file in an XML or csv format which is sent
to the NAV system, is their a best practice / recognised method to do this?
Hi,
It’s possible to create some kind of automation to periodically import external data into Dynamics NAV without user intervention (XML ports, web services,etc.) It depends exactly what steps you want avoid user intervention.
I would definitely use a web service, though, as that will allow you to still use the NAV business logic. That way you don’t insert directly into the tables and risk corrupted data. Going through the WS and business logic will catch any errors.
Ok I have a webservice called V1Import which is connected to a CodeUnit:
TestFile.OPEN(‘C:\Import.xml’);
TestFile.CREATEINSTREAM(TestStream);
XMLPORT.IMPORT(50000,TestStream);
XMLport 50000 is called V1Import and contains:
Node Name Node Type Source Type Data Source
head Element Table (Purchase Header)
Vendor-No Element Field ::Buy-from Vendor No.
DocType Element Field ::Document Type
And my xml file c:\Import.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
2
20000
I have a httppost program which sends data to a webservice, but does the above seem plausable? I get :
http 400 BAD REQUEST
Using a soap file with the payload of the xml file contained within.
There’s different ways to update your list, i suggest using a web service, but maybe all you need to do is to schedule a dataport that reads a csv file located in a shared directory.
I don’t want any user intervention from the user within the RTC.
A process / integration outside the environment will push the data into the Purchase Header table so that it appears HERE
The data can come in either a csv or xml format, be appropriately formatted anyway required by NAV.
At this point just the No. & Buy-from Vendor Number will do, it’s just the method to do it. The tables are not nullable so I can’t practically just write to them (which I’ve tried 143 fields later!)
file produced by my system > httppost > Dynamics NAV 2009 > populates THIS list
That’s all it is.
Ok, having tried somewhat unsuccessfully to try manually populate the table, I have a CodeUnit which is successfully importing the data in a correctly formatted XML file into the the purchase header table!
I have published this as a webservice which is visible in the http://dynamicsnav2009:7047/DynamicsNAV/WS/CRONUS%20International%20Ltd/services list called V1Import as http://dynamicsnav2009:7047/DynamicsNAV/WS/CRONUS International Ltd/Codeunit/V1Import" xmlns=“http://schemas.xmlsoap.org/disco/scl/” />
Assuming the XML is the payload, how do I find out the format of the soap file to go along with the httppost?
I don’t have to use a webservice. If this isn’t easy, is there some kind of filewatcher within NAV that can poll a directory for a filetype and if found, run the CodeUnit?
This solution must be deployable and as such be as easy as possible to install and setup!
To create an web service in Dynamics NAV it’s an easy process. Also has you had suggested, you could use a scheduler to periodically run a codeunit to import some kind of file. it’s depends you requirements.
I like the idea of periodically running the Codeunit, the emphasis of this being done outside the NAV interface. I’m running fin.exe but obviously all that does is open the Classic client which isn’t what I want.
All the work needs to be done on the server and reflected on the client machines, i.e.
a correctly formatted XML is put into x:\adirectory by my software on the server.
A CodeUnit runs and imports the xml file as data into the database populating the Purchase Header.
Up to here I have working nicely. Currently I have to manually click the RUN button in the Classic Client to action the CodeUnit, all I need is a way of automatically calling the CodeUnit without the need to run the client.
I have tried it publishing it as a webservice fine, but it’s knowing what to do with it, i.e. I have a XML file, I have a webservice, what now? 
You said you are running fin.exe and not finsql.exe, so I’m afraid you might not be on SQL Server. But if you are, here is a nice way of calling the web service from SQL.
http://mibuso.com/blogs/ara3n/2009/11/14/replacing-nas-with-sql-jobs-and-nav-web-service/
Thanks Matt but I’ve already looked at this and it isn’t realistic. We have to install this as an integration on a lot of customer’s sites, there’s no way they’d allow it, it has to be as simple and unobtrusive as we can.
My software essentually runs a file (let’s call it petesfile.def) which as well as doing other tasks specific to my software, creates a correctly formatted xml file containing the relevant data for the Purchase Header (for these purposes called c:\PHExport.xml).
I have a working CodeUnit referencing filename:=(‘c:\PHExport.xml’); and running it without confirmation uploads it perfectly.
The final piece of the puzzle is to automate this process so that rather than having to load the classic client and pressing run on the CodeUnit, can this be done in a batch file / script?
Hi Pete,
you could also use the NAV Application Server (Client without User Interface, run as a service) and then use e.g. the Job Queue to run your codeunit periodically.
Or write your own .NET app and schedule it using Windows Task Scheduler. At the end of the day the only way you’re going to have it automatically import is through some other process that is already running. Whether that be SQL Jobs, NAV Application Server, Windows Task Scheduler, or something else.
Hi Guys,
Ok Application Server installed which went quite smoothly!
Still on the server:
Load Classic Client > Administration > Application Setup > Job Queue > Job Queue Entries > F3
Added the the job in the job queue to run my CodeUnit, set the reoccurence to everyday, start time etc …
I check the List, it’s in the queue and checked for recurring.
Wait 5 minutes or so, It’s not running the CodeUnit.
I’m presuming I need to do something else not in the help?
Hi Pete,
two things to check, that come to my mind:
is the job Queue activated? in the “Job Queue Setup” you have activate the field “Job Queue active”.
is the Application Server setup correctly? Startup Parameter has to be JOBQUEUE.
As a small aside, since it sounds like you are developing some sort of add-on solution, remember that customers who buy this product have to be licensed for at least one application server. More if they are being used for tasks other than the job queue. In the US at least they were a little over $1000 last I checked. Just a heads up if you were not aware.
Hi Matt,
you’re right for the “old” Module based licensing. With the Business Ready Licensing models (at least in EMEA) one Session for the Application Server is included in the base license.
Hi Daniel,
I’ve set it up to the best of my knowledge, here is the startup command:
nassql.exe appservername=VersiononeNAVService, NETTYPE=TCP, servername=dynamicsnav2009, database=“Demo Database NAV (6-0)”, company=“CRONUS International Ltd.”, nettype=tcp, startupparameter=“JOBQUEUE”, objectcache=40000, installasservice
Which starts it and doesn’t return any errors.
HERE is a screen shot you may find useful.
To re iterate, if I run the CodeUnit manually, it works successfully in that it adds to the Purchase Header which is what I’m trying to automate.
I think, you have to enter JOBQUEUE in Paramenter string of Job Queue Entry Card
and in recurence tab, days, Starting Time and No. of Minutes between Runs (24*60=1440)
In services, your NAS-SQL should be running