How can I automate tickets with Javascript via Tampermonkey

calebwoolsey
Kilo Contributor

I'm working with Tampermonkey within Chrome to automate a ticket route based on keywords found in the Short Description when submitted by an end user.

A lot of these self submitted tickets for access can be auto routed, I'm attempting to create a script that fills out the ticket and prompts either Yes or No if the technician would like to route the ticket to the resolver group input by the script.

I've currently got the code to read in the short description, find the keyword based on an array, set the index of that array to match with other arrays used to set Category, Subcategory, Subcategory Type, and Configuration Item.

When I try to use g_form.setValue() function or "document.getElementById('id').value =" it will input the data both into the work notes and into the Resolver Field, but when I hit save, it doesn't save these fields and takes it right back to the default (Service Desk resolver and no work notes).

Does anyone know a way to set the resolver group from a Tampermonkey JavaScript perspective?

Edit:

I found a log in the console, but still have no idea why this is occurring. I'm by all means a newbie when it comes to coding and especially understanding AJAX.

Error:

" ** WARNING *** GlideAjax.getXMLWait - synchronous function - processor: AJAXGlideRecord"

I'm not sure what this error means but from what I've researched it look like a timeout error when communicating with server, but even when I try to put the function through a setTimeout() function for Javascript to adjust for latency (like I had to do for Categorization) it still won't work.
Any help or thoughts is helpful.

Edit 2:

I was able to solve the Resolver Group issue as I was inputting incorrect data (thank you to notes below for helping me find this information).

Now the issue is that Work Notes won't save.

Work Notes are input into the ticket and when I hit save, they simply disappear and don't actually save to the ticket.

I'm using gel or document.getElemenyById("id").value +=

for this, but it's not saving correctly. Should I be using g_form?

1 ACCEPTED SOLUTION

g_form.setValue('assignment_group', 'this should be the sys id of group', 'this should be the display value of group');


View solution in original post

7 REPLIES 7

Kalaiarasan Pus
Giga Sage

I am not sure what is TamperMonkey but you can do this within ServiceNow itself using assignment rules.



Defining Assignment Rules - ServiceNow Wiki



Any reason not to use this feature?


Hi there!


Yes I'd like to do this within ISM using assignment rules or using templates (Which could easily do what I'm trying to do) but the use of these has been removed by the client company so we are attempting to find a workaround that allows us similar functionality.


We don't have access to setup assignment rules or admin access within ISM so we're trying to right scripts in Javascript to do it for us.


Tampermonkey just injects a specific code on top of a loaded page. I've written some Javascript in Tampermonkey to be loaded on top of ISM once it loads to run certain functions, it's only Work Notes and Resolver Group that has issues now, the Configuration Item and Categorization works just fine.



I'm trying to figure out why the g_form.setValue('assignment_group', value, value); won't work even thought I've defined value and the console doesn't return an undefined. It gives me a glide issue with ajax that I'm not too certain about.


g_form.setValue('assignment_group', 'this should be the sys id of group', 'this should be the display value of group');


Ok so if I change the code to:


g_form.setValue('assignment_group', 'sys_display.sc_task.assignment_group', "APP-GDO");


The glide error still occurs, when I hit save within ISM it says "invalid update" and "Match not found, reset to original" under the resolver field.


Its looks like it's somehow not validating the data that's being input