- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2020 06:55 AM
Hi I am new to servicenow and wanted to create an array of sys_id with gliderecord
This is my current code using a single sys_id but what if I needed to do say 10 sys_id. How would i put that into an array? What is the best way to do this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2020 09:28 AM
Try below:
var arr = [];//pass your sys_id's comma separated
for(var i=0; i<arr.length; i++){
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id',arr[i]);
gr.query();
if(gr.next()){
gr.last_run_datetime = '';
gr.update();
}
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2020 08:58 AM
Hi jason,
You can use simply array use in java script:
var arrayDemo=[];
Example
- var order=new GlideRecord('sc_cat_item');
- order.addQuery('category.title','Computer & Telephony');
- order.addActiveQuery();
- order.query();
- var item_access = [];
- while(order.next()){
- item_access.push(order.getValue("sys_id"));
- }
- for(var count=0;count < item_access.length; count++){
- gs.log(item_access[count].name);
- }
Please mark as correct and helpful,If you find any help worthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2020 09:28 AM
Try below:
var arr = [];//pass your sys_id's comma separated
for(var i=0; i<arr.length; i++){
var gr = new GlideRecord('sys_data_source');
gr.addQuery('sys_id',arr[i]);
gr.query();
if(gr.next()){
gr.last_run_datetime = '';
gr.update();
}
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2020 10:28 AM
Thanks Prateek!
I had this same javascript written except i had 'var gr = new GlideRecord('sys_data_source'); on the outside of the for loop the whole time so it wouldn't run correctly. It was as simple as just adding it in the for loop smh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2020 11:11 AM
That would work. But that's a very inefficient way.