Fetching Sys IDs of selected records from related list to description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 09:31 AM
Hi,
I was trying something weird/new.
On Incident form, I have a related list. if I select few records and click on UI action 'Custom - Attach KB', then it should update the description with Sys ID of selected record and Incident Sys ID on Short Description.
I am getting Sys IDs of selected records, but not getting Incident Sys ID.
I am trying cutting URL and fetching Sys ID method.
I want to know, is it wrong here to get URL after clicking UI Action? if Yes, then what should be the approach?
Note:
1. Cant use current as related list is on 'kb_knowledge' table.
2. same goes for g_form.getUniqueValue().
UI Action:
UI Action Script:
function FetchFromList() {
var url_string = gs.getProperty("glide.servlet.uri") + gs.action.getGlideURI();
var start = url_string.indexOf("sys_id=") + 7;
var end = url_string.indexOf("sys_id=") + 39;
var sub_string_sys_id = url_string.substring(start, end);
var abc = new GlideRecord("incident");
abc.addQuery('number', 'INC0010329');
abc.query();
abc.next();
abc.description = "sys_idIN: " + g_list.getChecked();
abc.short_description = sub_string_sys_id;
abc.update();
}
OUTPUT - Incident Short Description and Description:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 10:27 AM
Hi @Arpit_S
Can you try this to get the incident sys_id and you can short description
//get incident sys_id
var uri = action.getGlideURI();
var path = uri.getFileFromPath();
var parentId = uri.get('sysparm_collectionID'); //sys_id of the incident
gs.addInfoMessage(parentId);
//get incident short description
var incShort = new GlideRecord("incident");
incShort.get(parentId);
var incidentShortDescription = incShort.getValue("short_description")
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 05:55 AM
Hi @Arpit_S ,
Did it resolve your issue, if so
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 07:50 AM
Hi Hemanth,
my apologies for delay in my response. It is not working. the requirement was dropped, not needed anymore. Thanks for the response.
End goal: In related list, we would have all knowledge articles, in that, Analyst will select few KB Articles, and these Articles needed to be attached to 'KB Attached' related list of particular Incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 10:50 AM - edited 12-12-2023 04:30 AM
If you log url_string and sub_string_sys_id, you'll probably find two things you'll need to be aware of: The script is running once for every record selected in the Related List, and the URL changes when the button is clicked. To extract the Incident sys_id you could start your script with:
var uri = action.getGlideURI();
var sub_string_sys_id = uri.get('sysparm_collectionID');
But since this is a Related List we have access to the parent object, which is the Incident record that is already loaded, so you can just use:
function FetchFromList() {
var abc = new GlideRecord("incident");
if (abc.get(parent.sys_id)) {
abc.description = "sys_idIN: " + g_list.getChecked();
abc.short_description = parent.sysid.toString();
abc.update();
}
}
or maybe even something like:
function FetchFromList() {
parent.description = "sys_idIN: " + g_list.getChecked();
parent.short_description = parent.sysid.toString();
parent.update();
}