Send XML File from MSMQ to NAVISION

Mauro
Member Posts: 4
I'm trying to make a connection between a website and navision v3.70 using MSMQ. This works fine with text files, I can send and receive text files but now I want to use XML files and it doesn't seem to work. This is the C/AL code for receiving XML files, does anybody know what the problem is.
Comcom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
InMsg := InMessage;
InStr := InMsg.GetStream;
CREATE(XMLDom);
XMLDom.load(InStr);
InsertMSMQXML(XMLDom.documentElement);
Globals
Comcom /Automation/ 'Navision Communication Component version 2'.CommunicationComponent
MQBus /Automation/ 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter
InMsg /Automation/ 'Navision Communication Component version 2'.InMessage
XMLDom /Automation/ 'Microsoft XML, v5.0'.DOMDocument
XMLNode /Automation/ 'Microsoft XML, v5.0'.IXMLDOMNode
InStr /InStream
This is the function that inserts a record when the XML file is imported.
InsertMSMQXML(xmlCustomerNode : Automation "'Microsoft XML, v5.0'.IXMLDOMNode")
MSMQTestData.TextValue := xmlCustomerNode.firstChild.firstChild.nodeValue;
IF NOT MSMQTestData.INSERT THEN
REPEAT
MSMQTestData."Entry No." := MSMQTestData."Entry No." + 1;
UNTIL MSMQTestData.INSERT
Comcom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
InMsg := InMessage;
InStr := InMsg.GetStream;
CREATE(XMLDom);
XMLDom.load(InStr);
InsertMSMQXML(XMLDom.documentElement);
Globals
Comcom /Automation/ 'Navision Communication Component version 2'.CommunicationComponent
MQBus /Automation/ 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter
InMsg /Automation/ 'Navision Communication Component version 2'.InMessage
XMLDom /Automation/ 'Microsoft XML, v5.0'.DOMDocument
XMLNode /Automation/ 'Microsoft XML, v5.0'.IXMLDOMNode
InStr /InStream
This is the function that inserts a record when the XML file is imported.
InsertMSMQXML(xmlCustomerNode : Automation "'Microsoft XML, v5.0'.IXMLDOMNode")
MSMQTestData.TextValue := xmlCustomerNode.firstChild.firstChild.nodeValue;
IF NOT MSMQTestData.INSERT THEN
REPEAT
MSMQTestData."Entry No." := MSMQTestData."Entry No." + 1;
UNTIL MSMQTestData.INSERT
0
Comments
-
Globals
Comcom /Automation/ 'Navision Communication Component version 2'.CommunicationComponent
MQBus /Automation/ 'Navision MS-Message Queue Bus Adapter'.MSMQBusAdapter
InMsg /Automation/ 'Navision Communication Component version 2'.InMessage
XMLDom /Automation/ 'Microsoft XML, v5.0'.DOMDocument
CurrNode /Automation/ 'Microsoft XML, v5.0'.IXMLDOMNode
ReturnedNode /Automation/ 'Microsoft XML, v5.0'.IXMLDOMNode
InStr /InStream
XMLDOMMgt/Codeunit/XML DOM ManagementComcom::MessageReceived(VAR InMessage : Automation "''.IDISPATCH") InMsg := InMessage; InStr := InMsg.GetStream; CREATE(XMLDom); XMLDom.load(InStr); InsertMSMQXML(XMLDom.documentElement);
I don't see much wrong here, only I would have sent the entire XMLDom into the function, and programmed the function to read the right nodes, so that would turn intoInsertMSMQXML(XMLDom);
You didn't tell us what type the MSMQTestData variable is, so I'll use a Customer record variable. So then the function changes (note the different parameter and the XMLDOMMgt parameter I added to the globals):InsertMSMQXML(parXMLDoc : Automation "'Microsoft XML, v5.0'.DOMDocument") Customer.INIT; CurrNode := parXMLDoc.documentElement; WITH XMLDOMMgt DO BEGIN IF FindNode(CurrNode,'customer_number',ReturnedNode) THEN IF STRLEN(ReturnedNode.text) > 0 THEN Customer."No." := ReturnedNode.nodeTypedValue; // repeat this part with all your nodes to build your customer record // you'll have to do type conversions on options, integers, decimals and booleans // take a look in the XML conversion codeunits in standard Navision for ideas END; IF NOT Customer.INSERT(TRUE) THEN ERROR('Failed to insert customer from XML Document');
I really have no idea what you are trying to do with this:IF NOT MSMQTestData.INSERT THEN REPEAT MSMQTestData."Entry No." := MSMQTestData."Entry No." + 1; UNTIL MSMQTestData.INSERT
Of course it gets a little tricky when you have to go into nodelists for repeating nodes, but there are plenty of examples in standard Navision XML codeunits.
HTH0 -
Thank you for your reply Daniel. It works!
For your information...
MSMQTestData is a Table with two fields: "Entry No." (integer) and "TextValue" (Text 50). This Table is for testing only, just to see if the data from the XML file is inserted into a table. Now I know this is possible, I'll start building the application.
The last part is to increase the "Entry No." If the number exist it does "Entry No." + 1 and checks if an insert is possible.
THNX Again!0 -
-
Hi i have a simular code to you but i cant get the messagerecived function to execute. how do you trigger it??? (my MSMQ is working and getting messages but nothing happends)0
-
If there is an error in your C/AL code then it looks like the MessageRecieve function isn't triggered. It doesn't show your messages.
So first you have to be sure that your code is correct. Are you trying to import a text file or an XML file?0 -
The codeunit monitoring the MSMQ must be a single instance codeunit, which starts a process in the background that can only be stopped by closing the Navision session from which it was started. A regular codeunit will not execute the messagereceived trigger.
To access the Single Instance property, open the codeunit in design mode, open the properties window and set the SingleInstance property to Yes.
Also, the MSMQ must be a non-transactional queue, and it will only work if you have just the common MSMQ objects installed.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