For this you should use Navision Application Server (NAS) and in Codeunit 1, NASHandler function some code should be written to run your desired codeunit.
For example for Commerce Gateway and ADCS there is code written in NASHandler function of codeunit 1.
As Far as I know, NAS keeps checking after certain interval (Timer setting in NAS, perhaps 30 seconds) and then code in NAS Handler is repeated after that interval.
Generally NAS is used for scheduling tasks which should run without user intervention
Wow there is quite a bit of false information in this thread.
For more information about NAS, read ‘w1w1atas.pdf’, which is in the Doc folder on the product CD. When NAS logs in, the system executes the NASHandler function in codeunit 1 once for each time that it logs in. There is no internal timer that checks this function every now and then, it is executed only once, when NAS logs in.
The startup parameter in NAS is used to manage WHAT it does. Typically, you would create a single instance codeunit, that contains some sort of automation object that keeps running, such as a timer object, or a COM component that runs with events. It’s not the NASHandler function that executes, it’s the functionality in the single instance codeunit that is started by the NASHandler function that executes.
The only event based MSMQ functionality that I know of is the NAV MSMQ Busadapter. It works very well once you know what the limitations are, and you know the messages are formatted exactly the right way. There is not a lot of flexibility in it and I don’t like it at all. I’ve used the MSMQ object model directly and tied it to a timer object. That way it’s not event driven, but that was not a requirement for me.
vt011 accurately describes what you need to do to make that work. There’s a help file on the product CD called ‘devguide.chm’ (don’t know if it’s still there on the 2009 disks, but then it should be in the help file) that contains code samples how to do it. I’ve used that myself and I know for a fact that it works.
No that is not correct, NAS does not check codeunit 1 after certain interval. When NAS logs in, the NASHandler function in codeunit 1 is executed once. Depending on the startup parameter, code is then executed, and usually what you’d do is run a single instance codeunit, so that the NASHandler function only needs one call, and the actual functionality is handled elsewhere.
I would say it is incomplete, not wrong. There are many companies that use NAS only for scheduling tasks. As a developer you don’t see those because that comes out of the box with the Job Scheduler. I don’t have any numbers on how NAS is used, so I don’t think anyone can say whether the statement is true or false.
I got little confused at that time. In fact I have used BizTalk (CommerceGateway) and for which NAS was used and it was/ is codeunit BizTalk Appln. Srv. Startup which has a timer
(Commerce Gateway Timer’.Timer) that keeps checking.
And the NAS Handler infact just starts/ initiates BizTalk Appln. Srv. Startup codeunit when the NAS is started.
I’ve already done this.
You need to configure this:
A private MSMQ listener.
Install and setup the NAS and modify the Codeunit 1 to receive the NAS Startup parameter.
In my case, when Codeunit 1 receives the nas startup parameter, run another Codeunit in which I added the code to read messages from MSMQ.
Codeunit have this global vars:
MQBus Automation ‘Navision MS-Message Queue Bus Adapter’.MSMQBusAdapter
CC2 Automation ‘Navision Communication Component version 2’.CommunicationComponent → WithEvents = Yes.
InMsg Automation ‘Navision Communication Component version 2’.InMessage
InS InStream
Txt Text (100)
Function OnRun:
IF ISCLEAR(MQBus) THEN
CREATE(MQBus);
IF ISCLEAR(CC2) THEN
CREATE(CC2);
CC2.AddBusAdapter(MQBus,1);
Make sure that you do not receive mor than 4MB with your Message Queue at a time. Otherwise you get very weird and misleading error messages about insufficient memory.
Rather divide your data into chunks and transfer them one by one.
With the code sample I have, when the MSMQ receive a message, this is received in Navision automatically in seconds.
In my case, I use an external application to send a message to MSMQ with a shipment number. In this moment, my Codeunit (with the code i posted before) receive the message with the number and automatically register and print the corresponding shipment.
Since MSMQ receives the message and this is processed in Nav, it took only a few seconds.
On the other hand, the link you posted, helped me too much to make this development.
You have everything you need in the links that are already provided. That example looks alright. It seems to be taken out of a real life implementation (just like Raul’s example) so it must work, and looks exactly like the code in the samples that have already been given to you. It’s much easier to use an XMLPort to process your XML though, that one uses MSDOM to parse the XML. Nothing wrong with that, but XMLPorts are much easier.
Like I said before, the MSMQ Busadapter that comes with NAV is event driven, so when the message comes in, the MessageReceived trigger fires (as long as you implement this in a single instance codeunit). All the things you need are in the links in this topic. You have all the ingredients to work on YOUR implementation and make it work.
Thanks for your great support. Finally my implementation is working as per you guys suggested. Only problem is that whenever my codeunit get executed it shows following error:
This message is for C/AL programmers:The stream cannot find a zero-terminated string.The stream may be invalid, or the (variable or requested) size may be too small.