Send XML File from MSMQ to NAVISION

MauroMauro Member Posts: 4
edited 2004-11-29 in Navision Attain
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

Comments

  • DenSterDenSter Member Posts: 8,307

    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 Management
    I don't know about the v5.0 part, I've only used v3.0 so far, but that should work pretty much the same.
    Comcom::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 into
    InsertMSMQXML(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.

    HTH
  • MauroMauro Member Posts: 4
    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!
  • DenSterDenSter Member Posts: 8,307
    Graag gedaan Mauro 8) altijd leuk om te kunnen helpen.
  • Red_sweRed_swe Member Posts: 4
    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)
  • MauroMauro Member Posts: 4
    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?
  • DenSterDenSter Member Posts: 8,307
    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.
Sign In or Register to comment.