- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:06 AM
I need to create a stand-alone script that can be manually run. When executed, the script will perform a query of all non-resolved tickets for the current day, in a particular location. I'm new to scripting Service-Now, but not programming in general.
I have been searching through the examples, but I have not found anything like this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:22 AM
The best way to do this is get the results that you want in a list view, then copy the query.
For example, let's say we want to work off the task table to grab all tickets regardless of type. Go to a task list like so:
This gives me: active=true^location=ce3e85f037d0200044e0bfc8bcbe5d13
Now, go to scheduled job or fix script and craft your query:
var task = new GlideRecord('task');
task.addEncodedQuery('active=true^location=ce3e85f037d0200044e0bfc8bcbe5d13');
task.query();
while(task.next()){
//Do something
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:22 AM
The best way to do this is get the results that you want in a list view, then copy the query.
For example, let's say we want to work off the task table to grab all tickets regardless of type. Go to a task list like so:
This gives me: active=true^location=ce3e85f037d0200044e0bfc8bcbe5d13
Now, go to scheduled job or fix script and craft your query:
var task = new GlideRecord('task');
task.addEncodedQuery('active=true^location=ce3e85f037d0200044e0bfc8bcbe5d13');
task.query();
while(task.next()){
//Do something
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 10:13 AM
Great! This will get me closer to what I needed. One final question and I think I can guess the answer.
Can the script you posted be done as a VBScript?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 11:01 AM
You want to pull it to an external source? You can use VB and REST or SOAP to grab data. I don't believe there is a way to use VB inside the tool.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 11:06 AM
That's EXACTLY what I'm trying to do. It needs to run a quick query, take the results and perform some processing after the data comes back.
I know it's possible to use SOAP inside VBScript (or more likely, VB.NET) and capture the results. Just getting over this initial hurtle will get me much closer to my goal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 11:31 AM
Try these:
Table API - ServiceNow Wiki //This does not have a VBScript example, but you can see how it is done with 6 languages and make inferences based on that
VBScript REST Example - REST - Universal Devices Forum //This is a small REST example, not for SN, but, once again, inferences can be made