Hi Guys,
Following is code i copied from MSDN Talking to Navision and modified for my specific usage.
I am facing problem in reading the Specific node. I am getting an error in "XMLNodeItemCode.text" while i am trying to read one specific node.
Error: Message to CAL Prog. The Automation Variable has not been initiated.
Can any of you guys help me?
CC2::MessageReceived(VAR InMessage : Automation "''.IDISPATCH")
//Get the Message
InMsg := InMessage;
//Load the message into an XML document and find a node
IF NOT ISCLEAR(XMLDom) THEN
CLEAR(XMLDom);
CREATE(XMLDom);
XMLDom.load(InMsg.GetStream());
XMLNodeItemCode := XMLDom.selectSingleNode('itemcode');
XMLNodeAval := XMLDom.selectSingleNode('available');
//Calculate Stock
Item.RESET;
IF Item.GET(FORMAT(XMLNodeItemCode.text)) THEN begin
Item.CALCFIELDS(Item.Inventory);
XMLNodeAval.text := FORMAT(Item.Inventory);
END ELSE BEGIN
XMLNodeAval.text := FORMAT(0);
END;
//Open the response queue and create a new message
MQBus.OpenWriteQueue('.\private$\fromnavision',0,0);
OutMsg := CC2.CreateoutMessage('Message [url=queue://]queue://[/url].\private$\fromnavision');
OutS := OutMsg.GetStream();
//Fill the message and send it
OutS.WRITE(XMLDom.xml);
OutMsg.Send(0);
Thanks in Advance,
Logu
0
Comments
your issue is this line
XMLDom.selectSingleNode('itemcode');
selectSingleNode can't find the node.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
XMLDom.load(InMsg.GetStream());
XMLDom.save('C:\xmlfile.xml');
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
my xml file sample is
<?xml version="1.0" encoding="utf-8" ?>
- <inventory>
- <item>
<id>0</id>
<itemcode>logu</itemcode>
<availability>0</availability>
</item>
</inventory>
Please note i am not going to save it as a XML file.
We need to get as a MSMQ Xml string. After updating the availablity we need to return as a MSMQ Xml string.
Can you please help me reading the Item Code? (XML Node)
Thank you,
Logu
Reason I ask is... you shouldn't have to "initiate" an automation that 'stems' from an initiated automation. (No matter if the node is found or not. Result of your XMLDomNodeVar.Text would equal '' not an error.)
XMLNodeItemCode := XMLDom.selectSingleNode('inventory/item/itemcode');
XMLNodeAval := XMLDom.selectSingleNode('inventory/item/availability');
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Still it is showing error while it is in the line....
MESSAGE(XMLNodeItemCode.text);
Error is: This message for C/AL Programmers:
This automation variable has not been initiated.
You can initiate it by either creating or assigning it.
//CODE BIT
XMLDom.load(InMsg.GetStream());
XMLNodeItemCode := XMLDom.selectSingleNode('inventory/item/itemcode');
XMLNodeAval := XMLDom.selectSingleNode('inventory/item/availability');
MESSAGE(XMLNodeItemCode.text);
//CODE BIT
Variable Declaration as follows
XMLDom Automation 'Microsoft XML, v3.0'.DOMDocument
XMLNodeItemCode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
XMLNodeAval Automation 'Microsoft XML, v3.0'.IXMLDOMNode
Can you guys help me in solving this?
Thank you,
Logu
If you can do that fine then only other guess I have without actually testing with code of my own, try this...
(XMLRoot = IXMLDOMElement)
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n