Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed creating a form based on a vbscript

Status
Not open for further replies.

Malbordio

Programmer
Oct 19, 2014
12
PT
I have a vbscript that creates automatically a incident in ServiceNow. Tested and it works.
But I wish to make it more practical and funcional. I am looking for a form based on this vbscript in order to create the incident.
Can you guys help me compiling a form based on the vbscript I am posting bellow? Many thanks.

Option Explicit

Const gServiceNowUser = "username"
Const gServiceNowPass = "password"
Const gServiceNowURL = "Class ServiceNowDirectWS
' Use this class to call ServiceNow Direct Web Services functions
' For documentation on the Direct WS API see:
'
Dim sEndpointURL, sTableName, sMethod, sResponsePath
Dim oWSRequest, oWSRequestDoc, oWSResponseDoc
Dim oWSRequestEnvelope, oWSRequestBody, oWSRequestOperation

Public Sub SetMethod (tableName, method)
' This function must be called BEFORE Post to initialize the class
' method must be "insert", "update", "getKeys", "get" or "getRecords"
sTableName = tableName
sMethod = method
sResponsePath = "/soap:Envelope/soap:Body/" & sMethod & "Response/"
sEndpointURL = gServiceNowURL & sTableName & ".do?SOAP"
If (sMethod = "get" Or sMethod = "getRecords") Then
sEndpointURL = sEndpointURL & "&displayvalue=all"
End If
Set oWSRequest = CreateObject("MSXML2.XMLHTTP")
Set oWSRequestDoc = CreateObject("MSXML2.DOMDocument")
Set oWSRequestEnvelope = oWSRequestDoc.createElement("soap:Envelope")
oWSRequestEnvelope.setAttribute "xmlns:soap", _
" Set oWSRequestBody = oWSRequestDoc.createElement("soap:Body")
Set oWSRequestOperation = oWSRequestDoc.createElement("tns:" & sMethod)
oWSRequestOperation.setAttribute "xmlns:tns", _
" & sTableName
oWSRequestDoc.appendChild oWSRequestEnvelope
oWSRequestEnvelope.appendChild oWSRequestBody
oWSRequestBody.appendChild oWSRequestOperation
End Sub

Public Function Post
' This function does the actual Web Services call
' It returns True if the call is successful and False if there is an error
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=' Post = True
Else
Set oWSResponseDoc = Nothing
Post = False
End if
End Function

Public Function Status
' If Post returns False then 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
' If method is "insert" then it can be used to obtain the sys_id of the inserted record
' If method is "get" then it can be used to obtain any field from the record
GetValue = oWSResponseDoc.selectSingleNode(sResponsePath & fieldname).text
End Function

Public Function GetRowCount
' This function may be called after Post if the method is "getRecords"
' It returns the number of records in the result set
Dim sResultsPath, oNodeset
sResultsPath = sResponsePath & "getRecordsResult"
Set oNodeSet = oWSResponseDoc.selectNodes(sResultsPath)
getRowCount = oNodeSet.length
End Function

Public Function GetRowValue(rownum, fieldname)
' This function may be called after Post if the method is "getRecords"
' It returns a single field from a single record
Dim sRowPath, sFieldPath
sRowPath = sResponsePath & "getRecordsResult[" & rownum & "]/"
sFieldPath = sRowPath & fieldname
GetRowValue = oWSResponseDoc.selectSingleNode(sFieldPath).text
End Function

End Class

' Specify the ticket values
Dim wsInsertIncident : Set wsInsertIncident = New ServiceNowDirectWS
wsInsertIncident.SetMethod "incident", "insert"
wsInsertIncident.SetValue "short_description", "Incident Test"
wsInsertIncident.SetValue "description", "Incident Test"
wsInsertIncident.SetValue "caller_id", "My Username"
wsInsertIncident.SetValue "u_category", "Category Name"
wsInsertIncident.SetValue "u_subcategory", "Sub Category Name"
wsInsertIncident.SetValue "u_masiva", "Massive"

' 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
 
You could use htas. Basically an html page which you just rename to hta.
 
I agree with XWB, an HTA is an easy way to go, or you could convert to using PowerShell and use native Windows Forms. You can learn about adding your code to an HTA here: [link]http://technet.microsoft.com/en-us/library/ee692768.aspx[/url]

I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
With lots of help, I was able to have a form based on vbscript and with some hta combined. It's working as expected, it created the incident after filling the entries of the form.

Thanks for your efforts.

I am still after some more adjustments on this form. I am going to make a new post.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top