- 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:09 AM
You will probably want either a fix script or scheduled job. Depending on if you want it to run by it self and manual or just manually. What do you mean on the particular location? So i can help you with a draft of some code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:20 AM
var gr = new GlideRecord('incident');
gr.addEncodedQuery('sys_created_onONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)');
gr.addActiveQuery();
gr.addQuery('u_user_location','Mississippi');
gr.query();
while(gr.next) {
//dostuff
//
//
gr.update();
}
Here is a pretty generic version of what it would look like!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:23 AM
Interesting. So I would need to run this as a javascript program?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 06:28 AM
Yep! The filter set up below is also a very helpful tool. I just wanted to show you a few different types of queries since you said you are new to service now and it will be helpful to know! But going Mike's way will deffinently be easier for your problem right now.
Thanks