Jump to content

automation service now


kistoff
 Share

Recommended Posts

My company recently switched from Remedy to Service-now (https://demo.service-now.com, login itil itil) and I am trying to make some scripts to take away some repetitive work. I had some that worked well for the Remedy client, but since Service-now is web based I am not sure how/if AutoIT will work.

I tried using some IE.Au3 commands, but I am a novice with AutoIT and unsure of how to figure out how to interact with this website. I would like to be able to modify fields in a ticket, category, subcategory, etc. and update the ticket.

If I open a ticket and inspect the fields I want to modify for the category and subcategory I get the following.

<select name="incident.category" id="incident.category" style="width: 160px;" onchange="onChange('incident.category');">

<select name="incident.subcategory" id="incident.subcategory" style="width: 160px;" onchange="onChange('incident.subcategory');">

I am trying to do something like this below.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

$Form1 = GUICreate("Form1", 178, 106, 840, 229)
$Button0 = GUICtrlCreateButton("Button1", 8, 8, 75, 25)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
If $nMsg = $Button0 Then SN()
EndSwitch
WEnd

Func SN()
$oIE = _IEAttach("https://demo08.service-now.com/navpage.do")
$Category = _IEGetObjByName($oIE, "incident.category")
$SubCategory = _IEGetObjByName($oIE, "incident.subcategory")
_IEAction($Category, "Hardware")
_IEAction($SubCategory, "Keyboard")
EndFunc ;==>SN
Link to comment
Share on other sites

I haven't used service-now but when browsing their website I found this "Scripting" page.

Maybe service-now or the consultant who helped you to customize and implement the product can give you some hints how to automate the tool.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The team we have for service now is pretty busy with fixing things and working on improvements, so I am pretty far down on the list and do not know when they will have time to help me. I was trying to see if I could do it with AutoIT since I like it and have used it before. I am going to look some more into the scripting they have and maybe check out some things on their forums.

Link to comment
Share on other sites

Get a pointer to the IE instance like you did:

$oIE = _IEAttach("https://demo08.service-now.com/navpage.do")

use that to get a ref to the form containing the select box.

$oForm = _IEFormGetObjByName($oIE,"FORM_NAME_HERE")

Then use $oForm to get a pointer to the select box:

$oCategory = _IEFormElementGetObjByName($oForm,"incident.category")

Make your selection from the box:

_IEFormElementOptionselect($oCategory,"Hardware",1,"byValue")

Yay!! Finally something on here that I'm good at :)

EDIT: We're about to start using Service-Now at work too. I'll try it once I'm back in my old menial serial mode job.

Edited by gruntydatsun
Link to comment
Share on other sites

Cool, thanks for the help! Maybe we can bounce ideas off each other once you start using service-now. It seems I am still not able to figure this out. I guess it is a problem with the form name I am using, I used the developer tools in IE to find the name.

I found this which I think is the right form.

<form name="incident.do" id="incident.do" onkeypress="return enterSubmitsForm(event,'false')" action="incident.do" method="post" accept-charset="UTF-8">

If I run this it doesn't work and displays "Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch"

#Include <IE.Au3>

$oIE = _IEAttach("ServiceNow IT Service Management Suite")
$oForm = _IEFormGetObjByName($oIE,"incident.do")
$oCategory = _IEFormElementGetObjByName($oForm,"incident.category")
_IEFormElementOptionselect($oCategory,"Hardware",1,"byValue")
Edited by kistoff
Link to comment
Share on other sites

After a lot of forum reading, trial and error, I finally figured it out.

#include <IE.au3>

$oIE = _IEAttach("https://demo19.service-now.com/navpage.do", "URL")
$oForm = _IEFrameGetCollection($oIE, 0)
$oCategory = _IEGetObjByName ($oForm, "incident.category")
_IEFormElementOptionselect($oCategory,"Hardware",1,"byValue")
Link to comment
Share on other sites

Well I am stuck again... If I try to set an element and then set the next one right after (subcategory) the page does not update in time and it fails to set the next element. I could use Sleep() to wait, but that could fail depending on the speed of the connection. Is there a way to wait for the frame/element/form (I am not sure which one I would need to wait on) to load before setting the next element?

WinWait does not seem to work and I tried _IEloadwait, but can't seem to figure it out. There is a little loading image that appears as the page is updating, could I use that some how to find when the page has loaded?

Loading animation info

<IMG style="VISIBILITY: hidden" id=show_loading_gif border=0 src="images/loading_anim2.gifx" width=16 height=16>

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>

Global $Button[1]

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 178, 106)
$Button[0] = GUICtrlCreateButton("Button0", 8, 8, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then Exit
If $Msg = $Button[0] Then Hardware()
WEnd

Func Hardware()
$oIE = _IEAttach("https://demo11.service-now.com/navpage.do", "URL")
$oForm = _IEFrameGetCollection($oIE, 0)
$oCategory = _IEGetObjByName($oForm, "incident.category")
_IEFormElementOptionSelect($oCategory, "Hardware", 1, "byValue")
;wait here
$oSubcategory = _IEGetObjByName($oForm, "incident.subcategory")
_IEFormElementOptionSelect($oSubcategory, "Keyboard", 1, "byText")
EndFunc ;==>Hardware
Edited by kistoff
Link to comment
Share on other sites

Yeah... sometimes if the page doesn't load via http (javascript etc.) the ie wait event doesn't work. If you know for certain that the next object you're attempting to access is going to show up, run a loop looking for it until it does show up.

EDIT: Maybe loop it with a Sleep(100), after 50 attempts (5 seconds) consider it timed out.

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I think I have it worked out and I thought I would post the code in case anyone is/was interested.

Edit: tooltips were just so I could see it working.

Func _IEWaitForImg()
Local $i = 0
While $i <= 5
Local $oIE = _IEAttach("https://demo11.service-now.com/navpage.do", "URL")
Local $oImg = _IEImgGetCollection($oIE, 3)
Local $sInfo = $oImg.style.visibility
If $sInfo = "visible" Then
ToolTip("Visibility: " & $oImg.style.visibility)
Sleep(100)
$i = 0
ElseIf $sInfo = "hidden" Then
ToolTip("Visibility: " & $oImg.style.visibility)
Sleep(100)
$i = $i + 1
EndIf
WEnd
EndFunc ;==>_IEWaitForImg
Edited by kistoff
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...