无法获得记录'使用SOAP到ServiceNow与VBA,获取错误:500内部服务器错误

时间:2016-06-30 13:27:04

标签: vba soap servicenow

以下是从Incident表格中通过 ServiceNow 获取记录的代码。

我收到错误:500服务器内部错误

我需要我的代码来获取属于特定分配组的所有记录,最好一次查询多个分配组。

Dim sName, sEndpointURL, sResponsePath
Dim oWSRequest, oWSRequestDoc, oWSResponseDoc
Dim oWSRequestEnvelope, oWSRequestBody, oWSRequestOperation

Public Sub SetName(name)
    ' This function must be called BEFORE Post to initialize the class
    sName = name
    URL = "http://schemas.xmlsoap.org/soap/envelope/"
    sEndpointURL = gServiceNowURL & sName & ".do?SOAP"
    sResponsePath = "/soap:Envelope/soap:Body/executeResponse/"
    Set oWSRequest = CreateObject("MSXML2.XMLHTTP")
    Set oWSRequestDoc = CreateObject("MSXML2.DOMDocument")
    Set oWSRequestEnvelope = oWSRequestDoc.createElement("soap:Envelope")
    oWSRequestEnvelope.setAttribute "xmlns:soap", _
                                    URL
    Set oWSRequestBody = oWSRequestDoc.createElement("soap:Body")
    Set oWSRequestOperation = oWSRequestDoc.createElement("tns:execute")
    oWSRequestOperation.setAttribute "xmlns:tns", _
                                     "http://www.service-now.com/" & sName
    oWSRequestDoc.appendChild oWSRequestEnvelope
    oWSRequestEnvelope.appendChild oWSRequestBody
    oWSRequestBody.appendChild oWSRequestOperation
End Sub

Public Function Post()
    ' This function does the actual Web Services call
    oWSRequest.Open "POST", sEndpointURL, False, gServiceNowUser, gServiceNowPass
    oWSRequest.setRequestHeader "Content-Type", "text/xml"
    oWSRequest.send oWSRequestDoc.XML
    If oWSRequest.Status = 200 Then
        Set oWSResponseDoc = CreateObject("MSXML2.DOMDocument")
        oWSResponseDoc.LoadXML oWSRequest.responseText
        oWSResponseDoc.setProperty "SelectionLanguage", "XPath"
        oWSResponseDoc.setProperty "SelectionNamespaces", _
                                   "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
        Post = True
    Else
        Set oWSResponseDoc = Nothing
        Post = False
    End If
End Function

Public Function Status()
    'If Post returns False call this function to obtain the HTTP status code
    Status = oWSRequest.Status
End Function

Public Function StatusText()
    ' If Post returns False then call this function for the error text
    StatusText = oWSRequest.StatusText
End Function

Public Sub SetValue(fieldname, fieldvalue)
    ' This function must be called BEFORE Post
    Dim oChild
    Set oChild = oWSRequestDoc.createElement(fieldname)
    oChild.appendChild (oWSRequestDoc.createTextNode(fieldvalue))
    oWSRequestOperation.appendChild (oChild)
End Sub

Public Function GetValue(fieldname)
    ' This function must be called AFTER Post
    GetValue = oWSResponseDoc.SelectSingleNode(sResponsePath & fieldname).Text
End Function

0 个答案:

没有答案