You are viewing limited content. For full access, please sign in.

Question

Question

How to retrieve an HTTP response in a VB script and update a token?

asked on October 28, 2015

We have a VB script that executes a GET...here's a snippet of the portion of the code that does this....

 

            query = query.Replace("COMPANY#", GetTokenValue("Getallfldsfrominvoice_Lawson Company").ToString())
            query = query.Replace("INVOICE#", GetTokenValue("Getallfldsfrominvoice_Invoice Number_1").ToString())
            query = query.Replace("VENDOR#", GetTokenValue("Getallfldsfrominvoice_Vendor ID").ToString())
            query = query.Replace("PRODLINE#", LawPDL)
            request = CType(WebRequest.Create(query), HttpWebRequest)
            request.Method = _GET
            request.Credentials = credentials
            request.UserAgent = userAgent
            request.CookieContainer = cookies
            request.Timeout = _timeout

            'Look for the answer
            response = CType(request.GetResponse, HttpWebResponse)
            response.Close()

 

This returns XML code similar to the following.....

 

  <?xml version="1.0" encoding="ISO-8859-1" ?> 
- <XAP99.1>
- <AP99.1>
  <_PDL>TEST</_PDL> 
  <_TKN>AP99.1</_TKN> 
  <_LFN>TRUE</_LFN> 
  <_PRE>TRUE</_PRE> 
  <TC>AP99.1</TC> 
  <FC>C</FC> 
  <ORIGINATOR /> 
  <AP99WORK-NAME>E:\tmp2937491_6.dat</AP99WORK-NAME> 
  <APP-PAY-GROUP>9999</APP-PAY-GROUP> 
  <PAY-NAME>Pay Group</PAY-NAME> 
  <APP-VENDOR>222</APP-VENDOR> 
  <VEN-VENDOR-VNAME>VENDOR NAME</VEN-VENDOR-VNAME> 
  <HLD-HLD-CODE /> 
  <PT-HLD-CODE /> 
  <HLD-DESCRIPTION /> 
  <FILTER>Filter</FILTER> 
  <ENABLE-FILTER /> 
  <ENABLE-FILTER-X /> 
  <SEL-COMPANY>0</SEL-COMPANY> 
  <SEL-PROC-LEVEL /> 
  <APC-VEN-MESSAGE /> 
  <PT-APP-COMPANY>0</PT-APP-COMPANY> 
  <PT-APP-INVOICE>1234567</PT-APP-INVOICE> 
  <PT-APP-SUFFIX /> 
  <PT-APP-CANCEL-SEQ>0</PT-APP-CANCEL-SEQ> 
  <PT-APP-SEQ-NBR>0</PT-APP-SEQ-NBR> 
  <PT-APP-VOID-SEQ>0</PT-APP-VOID-SEQ> 
  <PT-APP-REC-STATUS>0</PT-APP-REC-STATUS> 
  <PAY-COMPANY>9999</PAY-COMPANY> 
  <LINE-FCr0 /> 
  <APP-COMPANYr0>9999</APP-COMPANYr0> 
  <APP-HLD-CODEr0 /> 
  <PT-APP-HLD-CODEr0 /> 
  <APP-PAY-IMM-FLAGr0>N</APP-PAY-IMM-FLAGr0> 
  <APP-VENDOR-DTLr0>222</APP-VENDOR-DTLr0> 
  <APP-INVOICEr0>1234567</APP-INVOICEr0> 
  <APP-SUFFIXr0 /> 
  <APP-INVOICE-TYPEr0 /> 
  <APP-DUE-DATEr0>20150101</APP-DUE-DATEr0> 
  <APP-DISC-DATEr0 /> 
  <APP-TRAN-PMT-AMTr0>9999.99</APP-TRAN-PMT-AMTr0> 
  <APP-COMMENTSr0>Add</APP-COMMENTSr0> 
  <APP-INV-CURRENCYr0>USD</APP-INV-CURRENCYr0> 
  <APP-CANCEL-SEQr0>0</APP-CANCEL-SEQr0> 
  <APP-SEQ-NBRr0>1</APP-SEQ-NBRr0> 
  <APP-VOID-SEQr0>0</APP-VOID-SEQr0> 
  <APP-REC-STATUSr0>0</APP-REC-STATUSr0> 
  <LINE-FCr1 /> 
  <APP-COMPANYr1 /> 
  <APP-HLD-CODEr1 /> 
  <PT-APP-HLD-CODEr1 /> 
  <APP-PAY-IMM-FLAGr1 /> 
  <APP-VENDOR-DTLr1 /> 
  <APP-INVOICEr1 /> 
  <APP-SUFFIXr1 /> 
  <APP-INVOICE-TYPEr1 /> 
  <APP-DUE-DATEr1 /> 
  <APP-DISC-DATEr1 /> 
  <APP-TRAN-PMT-AMTr1 /> 
  <APP-COMMENTSr1 /> 
  <APP-INV-CURRENCYr1 /> 
  <APP-CANCEL-SEQr1>0</APP-CANCEL-SEQr1> 
  <APP-SEQ-NBRr1>0</APP-SEQ-NBRr1> 
  <APP-VOID-SEQr1>0</APP-VOID-SEQr1> 
  <APP-REC-STATUSr1>0</APP-REC-STATUSr1> 
  <_HK>9999 222 0000</_HK> 
  <Message>Change Complete - Continue</Message> 
  <MsgNbr>000</MsgNbr> 
  <StatusNbr>001</StatusNbr> 
  <FldNbr>TC</FldNbr> 
  </AP99.1>
  </XAP99.1>

 

 

Within the VB script, how do I retrieve the value of the <Message> node and put it in a workflow token?

Thank you

0 0

Replies

replied on October 28, 2015 Show version history

Penny - There are a couple of ways to retrieve an xml node value from a string but the easiest is something like this;

        Protected Overrides Sub Execute()
            
            'In this example the data stream from the HTTPWebRequest should be
            'stored to a string variable...
            Dim xmlResponse As String
            
            'Instantiate a new XmlDocument...
            Dim xmlDoc As New System.Xml.XmlDocument
            Dim responseMessage As String

            'Load the response string into the xml document...            
            xmlDoc.LoadXml(xmlResponse)
            
            'Get the value of this specific node...
            responseMessage = xmlDoc.SelectSingleNode("//XAP99.1/AP99.1/Message").InnerText
            
            'Set the return token value...
            Me.SetTokenValue("ResponseMessage", responseMessage)

        End Sub

In the example above the assumption is that the returned XML string has a consistent structure containing the root and parent nodes<XAP99.1> and <AP99.1>

The value of the <Message> node will be available to other workflow activities as a token called 'ResponseMessage'.

0 0
replied on October 28, 2015

If the xml node structure is not consistent as in the example above you can also use something like this that will look for every <Message> node and append the inner text...

        Protected Overrides Sub Execute()
            
            'In this example the data stream from the HTTPWebRequest should be
            'stored to a string variable...
            Dim xmlResponse As String 
            
            'Instantiate a new XmlDocument, nodeList, and response string...
            Dim xmlDoc As New System.Xml.XmlDocument
            Dim nodeList As System.Xml.XmlNodeList
            Dim responseMessage As String = ""

            'Load the response string into the xml document...
            xmlDoc.LoadXml(xmlResponse)
            
            'Get a list of nodes with the tag <Message>...
            nodeList = xmlDoc.GetElementsByTagName("Message")
            
            'Step through each returned node and append the innertext...
            'NOTE: Assumption is that there is only one <Message> tag?
            For Each node As System.Xml.XmlNode In nodeList
                responseMessage &= node.InnerText
            Next

            'Set the token value to return...
            Me.SetTokenValue("ResponseMessage", responseMessage)

        End Sub

 

0 0
replied on October 28, 2015

Or you could just read the entire xml response string into a token in the script (as in the above script examples) and then use the stock 'Read XML' workflow activity to parse the message text...

In this example the script activity exposes a string token called 'httpResponse' and parses it looking for the first match on the <Message> node and storing the text as a token call 'ReturnMessage'

 

0 0
replied on October 29, 2015

Thank you very much for the quick response.  I have implemented the third option you suggested.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.