-2

I'm trying to retrieve a incident reference number when I run a vbscript. The script opens the ticket with the script ticket values in the code but it returns the following error: Error: Necessary object: 'oWSResponseDoc.selectSingleNode(...)'

The code I am using is

' Perform the insert and check the status
If Not wsInsertIncident.Post Then
  WScript.Echo "Error=" & wsInsertIncident.Status 
  WScript.Echo wsInsertIncident.StatusText
  WScript.Quit
End If

Dim strIncidentSysId, strIncidentNumber
strIncidentSysId = wsInsertIncident.GetValue("sys_id")
strIncidentNumber = wsInsertIncident.GetValue("number")
WScript.Echo "Inserted: " & strIncidentNumber

I know this worked in the past but today it doesn't. I don't know what has changed. Full script can be seen here:

https://servicenowsoap.wordpress.com/2013/10/26/vb-script/

Can you please help me? Many thanks!

Malbordio
  • 92
  • 3
  • 4
  • 20

1 Answers1

0

You need to use the SetMethod function before you can insert an incident. This is used to determine what action to take when you make the web call.

I tested this on a demo instance and it created the incident and returned a number.

' Specify the ticket values
Dim wsInsertIncident : Set wsInsertIncident = New ServiceNowDirectWS
wsInsertIncident.SetMethod "incident", "insert"
wsInsertIncident.SetValue "short_description", "Demo WS Incident"
wsInsertIncident.SetValue "description", "Demo WS Incident"
wsInsertIncident.SetValue "caller_id", "Abel Tuter"
wsInsertIncident.SetValue "category", "hardware"
wsInsertIncident.SetValue "subcategory", "mouse"

' Perform the insert and check the status
If Not wsInsertIncident.Post Then
  WScript.Echo "Error=" & wsInsertIncident.Status 
  WScript.Echo wsInsertIncident.StatusText
  WScript.Quit
End If

Dim strIncidentSysId, strIncidentNumber
strIncidentSysId = wsInsertIncident.GetValue("sys_id")
strIncidentNumber = wsInsertIncident.GetValue("number")
WScript.Echo "Inserted: " & strIncidentNumber

Dim objShell : Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.Popup "Inserted: " & strIncidentNumber,, "ServiceNow ticket!"
Kirk
  • 16,182
  • 20
  • 80
  • 112
  • Thanks for the help. I know the incident is created but did you get a popup window with the number? I'm not getting that on my side. I'm running directly the vbscript. Did you get that by using powershell? – Malbordio Aug 14 '17 at 22:04
  • Yeah, just from powershell. No popup, it's just in the output of the console. If you are running it directly, you'll need a popup. I've added a couple of lines to do a popup if that helps – Kirk Aug 14 '17 at 22:19
  • Sorry, still the same error, still no popup. You are trying to include a popup at the same time you already have an echo, is that right? Thanks for the help! – Malbordio Aug 14 '17 at 22:31
  • I can't reproduce your error unfortunately. I've pasted the full code I've used here. https://pastebin.com/sDSvJJnU Just save it to a `.vbs` file and change the 3 variables at the top, hopefully it helps. – Kirk Aug 15 '17 at 16:09
  • I've manage to correct the error. I've changed into this: `' Perform the insert and check the status If Not wsInsertIncident.Post Then WScript.Echo "Error=" & wsInsertIncident.Status WScript.Echo wsInsertIncident.StatusText Dim strIncidentSysId, strIncidentNumber strIncidentSysId = wsInsertIncident.GetValue("sys_id") strIncidentNumber = wsInsertIncident.GetValue("number") WScript.Echo "Inserted: " & strIncidentNumber WScript.Quit End If` – Malbordio Aug 15 '17 at 18:44
  • Yet, still not getting any popup alert after running the script by double clicking the vbs. Tried in 3 diferent OS's. Sorry. It's ok. Thx – Malbordio Aug 15 '17 at 18:47