- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2017 05:17 PM
Maybe this is a stupid question but for the life of me I cannot find any answers anywhere.
Firstly, I'm an administrator who writes code \ develops for automation \ a hobby and very new to ServiceNow and trying to get my head around how all this works.
I have a workflow which has a run script activity on it. There's some code in there which I think pulls data from a table using a GlideRecord. I want to simply run said part of code to see if it actually does what I think it does and see what data it pulls and how it references it but I cannot for the life of me figure out how to get the code to execute.
Any help would be greatly appreciated.
Actual code if required:
var checklist new GlideRecord('x_107342_morning_c_morning_checks_table');
checklist.orderByDesc('sys_created_on');
checklist.setLimit(1);
checklist.query();
if (checklist.next()) {
gs.print(checklist.getValue("sys_created_on"));
gs.print(checklist.getDisplayValue("sys_created_on"));
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2017 07:35 PM
Hi,
Elevate your roles and run this in Background script.
testRun();
function testRun {
var checklist = new GlideRecord('x_107342_morning_c_morning_checks_table');
checklist.orderByDesc('sys_created_on');
gs.print(checklist.getRowCount());
checklist.setLimit(1);
checklist.query();
if (checklist.next()) {
gs.print(checklist.getValue("sys_created_on"));
gs.print(checklist.getDisplayValue("sys_created_on"));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2017 07:35 PM
Hi,
Elevate your roles and run this in Background script.
testRun();
function testRun {
var checklist = new GlideRecord('x_107342_morning_c_morning_checks_table');
checklist.orderByDesc('sys_created_on');
gs.print(checklist.getRowCount());
checklist.setLimit(1);
checklist.query();
if (checklist.next()) {
gs.print(checklist.getValue("sys_created_on"));
gs.print(checklist.getDisplayValue("sys_created_on"));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2017 07:46 PM
Apparently it needed another () on the second line but this worked!
Updated script:
testRun();
function testRun() {
var checklist = new GlideRecord('x_107342_morning_c_morning_checks_table');
checklist.orderByDesc('sys_created_on');
gs.print(checklist.getRowCount());
checklist.setLimit(1);
checklist.query();
if (checklist.next()) {
gs.print(checklist.getValue("sys_created_on"));
gs.print(checklist.getDisplayValue("sys_created_on"));
}
}
Thank you very much kind sir!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2017 07:56 PM
Ah how did I miss that , thanks for correcting. Glad that it is working