- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:17 AM
Hi Team,
I need sys id of 100 records by passing short description. The short desc may contain ',(,& in it. How we can get sys id of this records,
eg: short description :
Discuss New Hire's Career Journey |
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:31 AM
Are you having a list of short descriptions that you need to look for the record sys_ids? If so, please try:
function getSysIds(shortDescriptions) {
var result = [];
var grIncident = new GlideRecord("incident"); //Replace with the table you want
grIncident.addQuery("short_descriptionIN" + shortDescriptions);
grIncident.query();
while (grIncident.next()) {
result.push(grIncident.sys_id);
}
return result;
}
//Usage: Example
var shortDescriptions = ["Discuss New Hire's Career Journey", "TEST SHort Description"];
var sysIds = getSysIds(shortDescriptions);
gs.info(sysIds);
//Results:
//Script: 690923053b6caed0e301de2a85e45a4b,690923053b6caed0e301de2a85e45a4b
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:35 AM - edited 03-27-2025 05:47 AM
Hi @preethigovi ,
You can write a script.
var sysid = [];
var gr = new GlideRecord("table_name");
gr.addQuery("short_descriptionLIKE
Discuss New Hire's Career Journey");
gr.setLimit(100); // Limiting 100 record to get the sys_id.
gr.query();
while(gr.next())
{
sysid.push(gr.sys_id);
}
gs.print(sysid);
For optimum result you can go to the table list view and build the query using filter and copy the filter. Use the copied filter in line gr.addQuery("paste_copied_filter_query")
If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:42 AM
since you only want 100 records, please use setLimit()
var shortDescription = "Discuss New Hire's Career Journey";
var gr = new GlideRecord('incident');
gr.addQuery('short_description', 'LIKE', shortDescription);
gr.setLimit(100);
gr.query();
var sysIds = [];
while (gr.next()) {
sysIds.push(gr.getValue('sys_id'));
}
gs.info('Sys IDs: ' + sysIds.join(', '));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 08:56 PM
Hello @preethigovi
To retrieve the sys_id of records where the short description contains special characters like ', ( &, try this script:
var sys_id_arr = [];
var gr = new GlideRecord('incident');
gr.addEncodedQuery("short_descriptionLIKE'^ORshort_descriptionLIKE,^ORshort_descriptionLIKE(^ORshort_descriptionLIKE&");
gr.setLimit(100);
gr.query();
while(gr.next()){
sys_id_arr.push(gr.getUniqueValue());
}
gs.print("Sys IDs: " + sys_id_arr.join(', '));
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 01:35 AM
Hi @preethigovi ,
I believe I have also provided correct solution.
You can also mark more than one correct solution as "accept the solution".
Regards,
Rohit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:38 AM
var records = new GlideQuery('incident')
.where('short_description', 'CONTAINS', ","|| ";")
.limit(100)
.select(['sys_id', 'short_description'])
.forEach(function(record) {
gs.print(record.sys_id + " - " + record.short_description);
});
Please mark any helpful or correct solutions as such. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:38 AM
var gr = new GlideRecord('incident'); // Replace with actual table
gr.addQuery('short_description', 'CONTAINS', "Discuss New Hire's Career Journey");
gr.query();
var count = 0;
while (gr.next() && count < 100) {
gs.print(gr.sys_id);
count++;
}
Please mark correct/helpful if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:41 AM
Hi @preethigovi ,
try following background script:
var records = new GlideQuery('incident')
.where('short_description', 'CONTAINS', ","|| ";")
.limit(100)
.select(['sys_id', 'short_description'])
.forEach(function(record) {
gs.print(record.sys_id + " - " + record.short_description);
});
Please mark any helpful or correct solutions as such. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 05:42 AM
since you only want 100 records, please use setLimit()
var shortDescription = "Discuss New Hire's Career Journey";
var gr = new GlideRecord('incident');
gr.addQuery('short_description', 'LIKE', shortDescription);
gr.setLimit(100);
gr.query();
var sysIds = [];
while (gr.next()) {
sysIds.push(gr.getValue('sys_id'));
}
gs.info('Sys IDs: ' + sysIds.join(', '));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader