The CreatorCon Call for Content is officially open! Get started here.

how to test \ execute "run script" scripts

johnrecz
Giga Contributor

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"));

}

1 ACCEPTED SOLUTION

Bharath40
Giga Guru

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"));


}


}


View solution in original post

3 REPLIES 3

Bharath40
Giga Guru

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"));


}


}


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!


Ah how did I miss that , thanks for correcting. Glad that it is working