The CreatorCon Call for Content is officially open! Get started here.

SOAP Insert via Excel VBA

rstimy
Kilo Explorer

Hi, I have had a requirement to create a new Problem ticket via SOAP using a VBA function in Excel as the trigger dropped on me.   I am able to get this working with REST, but I am missing something with SOAP.   I'm sorry, I don't have much knowledge or understanding of SOAP/XML.   Below is my code to create a new Problem with a short_description:

Function soapCreate()

      Dim xmlHtp   As New MSXML2.XMLHTTP

      Dim sURL       As String

      Dim sEnv       As String

           

      'details changed for posting

      snURL = "https://instance.service-now.com>/api/now/table/problem"

      snUser = "user"

      snPassword = "password"

      sEnv = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"

      sEnv = sEnv & "<SOAP-ENV:Envelope xmlns:tns=""http://www.service-now.com/problem"" xmlns:   SOAP -ENV = ""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:   SOAP -ENC = ""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:   m = ""http://www.service-now.com"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" SOAP - ENV: encodingStyle = ""http://schemas.xmlsoap.org/soap/encoding/"" >"

      sEnv = sEnv & "<SOAP-ENV:Body>"

      sEnv = sEnv & "<insert xmlns=""http://www.service-now.com"">"

      sEnv = sEnv & "<short_description xsi:type=""xsd:string"">This is a SOAP test</short_description>"

      sEnv = sEnv & "</insert>"

      sEnv = sEnv & "</SOAP-ENV:Body>"

      sEnv = sEnv & "</SOAP-ENV:Envelope>"

      With xmlHtp

              .Open "POST", snURL, False, snUser, snPassword

              .setRequestHeader "Host", ""

              .setRequestHeader "Content-Type", "text/xml"

              .setRequestHeader "soapAction", "CSV/Text" ' per the documentation

              .send sEnv

             

              Debug.Print .responseText

      End With

End Function

1 ACCEPTED SOLUTION

drjohnchun
Tera Guru

The Table API supports XML request format, but it's not the same as SOAP. For example, to insert a new Problem record with a Short Description, the request body would simply be



<request>


  <entry>


          <short_description>This is a SOAP test</short_description>


  </entry>


</request>



Can you set your sEnv to this and retry?



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


View solution in original post

3 REPLIES 3

drjohnchun
Tera Guru

The Table API supports XML request format, but it's not the same as SOAP. For example, to insert a new Problem record with a Short Description, the request body would simply be



<request>


  <entry>


          <short_description>This is a SOAP test</short_description>


  </entry>


</request>



Can you set your sEnv to this and retry?



Hope this helps.



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

Winner of November 2016 Members' Choice Award


This works and gives me the option to use it or the REST call.   Thank you for your help!


drjohnchun
Tera Guru

If using SOAP is a must, you might look into SOAP Web Service - ServiceNow Wiki