A couple of weeks ago I was asked to devise a solution that would allow a Navision v3.70 client to query an external Web Address and receive an XML document in response. I had never used automations etc before and quickly got confused, however this forum has provided useful tips so I’ld like to share my solution in return. If you say that this is too simple, then now I would agree with you, but when I started I was glad of all help and it was not possible to underestimate my ignorance! The scenario is that a user fills out a Navision form and then presses a command button. The command button runs code that communicates with the web site, receives a response, populates and redraws the form. Global definitions XMLDOMHTTP Automation ‘Microsoft XML, v3.0’.XMLHTTP XMLDom Automation ‘Microsoft XML, v3.0’.DOMDocument XMLNode Automation ‘Microsoft XML, v3.0’.IXMLDOMNode PayOffshore Text 250 (The parameter string) PayURL Text 250 (The URL eg https://xxx.yyy.com/zzzz/nnn.xml) TransactionAuthorisation Text 30 Form Variables TransactionNumber Text 30 Response Text 30 ErrorCode Text 30 ErrorMessage Text 30 Parameter1 Text 30 Parameter2 Text 30 Parameter3 Text 30 Parameter4 Text 30 Code in OnPush trigger PayOffshore := ‘& parameter1=’ + Parameter1 + ‘& parameter2=’ + Parameter2 + ‘& parameter3=’ + Parameter3 + ‘& parameter4=’ + Parameter4; IF ISCLEAR(XMLDOMHTTP) THEN CREATE(XMLDOMHTTP); XMLDOMHTTP.open(‘POST’,PayURL, FALSE); XMLDOMHTTP.setRequestHeader(‘Content-Type’,‘application/x-www-form-urlencoded’); XMLDOMHTTP.send(PayOffshore); IF ISCLEAR(XMLDom) THEN CREATE(XMLDom); XMLDom := XMLDOMHTTP.responseXML; TransactionAuthorisation := XMLDom.selectSingleNode(’//authcode’).text; TransactionNumber := XMLDom.selectSingleNode(’//transno’).text; Response := XMLDom.selectSingleNode(’//authorised’).text; ErrorCode := XMLDom.selectSingleNode(’//error/code’).text; ErrorMessage := XMLDom.selectSingleNode(’//error/message’).text; IF Response = ‘true’ THEN BEGIN Response := ‘APPROVED’; CurrForm.TransAuth.VISIBLE(TRUE); CurrForm.TransNo.VISIBLE(TRUE); CurrForm.ErrCode.VISIBLE(FALSE); CurrForm.ErrMess.VISIBLE(FALSE); END ELSE BEGIN Response := ‘REFUSED’; CurrForm.TransAuth.VISIBLE(FALSE); CurrForm.TransNo.VISIBLE(FALSE); CurrForm.ErrCode.VISIBLE(TRUE); CurrForm.ErrMess.VISIBLE(TRUE); END; CurrForm.UPDATE; CLEAR(XMLDom); CLEAR(XMLDOMHTTP); ____________________________________________________________ Sorry about the lack of indentation!
Thanks for sharing that with us David. This would make a great addition to the tips and trick area.
David, there is no doubt, that when a person gets started on a project, the hardest thing is just getting past that first step. The clasic 'Hello World" scenario. I know how many hours can be spent on the silliest little thing when you are trying to sort out the syntax and just getting it to work. Input like this is appreciated by everyone. Thanks.
Absolutely. Examples like this take days of the boring research off of development time.
Thanks for sharing the code. While on the subject of XML, I was on the Microsoft site and found this little presentation on XML Document Exchange. I know that XML Ports are not in the older versions, and would not be any use to Dave, but the presentation is worth a look anyway. www.microsoft.com/Businesssolutions/Navision/Demos/XMLDocumentExchangeI/index.html