incident record from a sys_id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 11:33 PM
How to get incident record from a sys_id in script??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 11:38 PM - edited 08-30-2023 11:38 PM
Hi @showsid02,
Try this sample scripts to get incident record using scripts.
var incidentRecord = new GlideRecord('incident');
incidentRecord.addEncodedQuery("sys_id=add_sys_id_here");
incidentRecord.query();
if (incidentRecord.next()) {
gs.info(incidentRecord.getValue('number')); // get or print other fields as per need
}
If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 11:41 PM
Or even easier, with a get:
var incidentRecord = new GlideRecord('incident');
if (incidentRecord.get('<<sys_id>>')){
gs.info(incidentRecord.getDisplayValue());
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 11:51 PM
Hi,
You can fetch record from any table with following script.
var grI = new GlideRecord('incident');
grI.get('91d704f7473b61106809afb8036d43fc');//SYSID of Incident
gs.print(grI.number);
Try this in Background script. It will work.
If you found my response helpful or relevant to your query, please consider clicking the "Helpful" button or giving it a "Like". This not only helps others identify useful replies but also encourages contributors like me to continue assisting the community. Thank you for your support!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2023 11:54 PM
Hi @GTSNOW,
You should never use a get without an if.
It makes sense to not do it in this case, because you probably already know this sys_id exists, however it can be taken as an example in an automated script, where it may not be the case there always is a valid sys_id which will lead to unintended results.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.