How to get sys id of the records in the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 02:35 AM
Hi ,
I have declared an array which contains the task numbers .
I want to push these records into another array which will contain its respective sys id.
And the list of all the records will be shown when i click the link present in the worknotes.
Unfortunately the code is redirecting to Record not found page upon clicking the link.
var taskMissingDetails = [];
var count= new GlideRecord('fm_expense_line')
count.addEncodedQuery("task.sys_class_name=sc_task^sys_created_onONLast 3 months@javascript:gs.beginningOfLast3Months()@javascript:gs.endOfLast3Months()");
if ((access == '' || company_id == '' || employee == '') ) {
taskMissingDetails.push(count.task.number.toString());
var uniqueTask = new ArrayUtil().unique(taskMissingDetails);// This is to get the unique records.
gr.addQuery('request', req);
gr.query();
while (gr.next()) {
gr.work_notes = taskMissing; // Update the worknotes with the link to the list of tasks with missing attributes.
gr.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 04:44 AM
Hi Shyna,
Please see below Script adding sysID,number and random string in single line. Be careful such customization can hammer performance.
var arrTask = [];
var sysID = []
var task = new GlideRecord('task');
task.query();
while(task.next())
{
arrTask.push(task.number.toString());
}
gs.print(arrTask);
for (i=0;i<arrTask.length;i++)
{
var Temp = arrTask[i].toString();
var task12 = new GlideRecord('task');
task12.addQuery('number',Temp)
task12.query();
while(task12.next())
{
sysID.push(task12.sys_id);
gs.print(sysID[i].toString() + 'MYLINK' + arrTask[i].toString());
}
}
gs.print(sysID);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 06:16 AM
When given a list of values and you want to retrieve different data for those records, I have found GlideQuery to be exceptionally handy and expressive. In the samples below, given a set of record numbers, I am able to retrieve not only the extra fields from the provided records, but I can dot-walk to related records, gather display values, etc... all without having to script additional queries:
var numbers = [ 'INC0010004', 'INC0010005', 'INC0009009' ];
var arr1 = [],
arrIDs = new GlideQuery( 'incident' )
.where( 'number', 'IN', numbers )
.select( 'number', 'sys_created_on', 'assigned_to$DISPLAY', 'assigned_to.department$DISPLAY' )
.reduce( function( arr, inc ){
arr1.push( inc );
arr.push( inc.sys_id );
return arr;
}, [] );
After running this, I get the two arrays shown in the attachments:
- arrIDs contains only the sys_ids.
- arr1 contains all selected fields.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2022 06:21 AM
For some reason, the editor would not allow me to save the screenshots inline.