Catalog variable value from script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 02:24 AM
Hi,
I have a catalog form where one of the variables are a reference to the cmdb for the user to select a server.
Based on this server I would like to have a read only field that dynamically lists any Application Service that has either has a "Depends on" or "Hosted on" type of relationship to the selected server.
How can I achieve this?
I assume that I need to work with the cmdb_rel_ci table and I guess I need to write a script in some way. I really appreciate any input I can get.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2025 08:00 AM
Think I solved my own question.... I was looking at normal client script but I guess the catalog client script is the correct place 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 03:24 AM
Hi,
I do not get your script to work.
I tried to simplify it to exclude issues but sill no luck.
When looking in the browser console, I get this issue.
"synchronous use not supported in Mobile or Service Portal unless message is already cached"
This is the Script include that I use to test with based on your input.
getRelatedServices: function() {
var serverId = this.getParameter('server_to_decomission');
if (!serverId) return '';
var serviceList = [];
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', serverId); // "Depends on" relationship
//gr.addQuery('type.name', 'IN', 'Depends on::, Hosted on::'); // Filter by relationship type
//gr.addQuery('parent.sys_class_name', cmdb_ci_service_auto); // Filter for app service class
gr.query();
while (gr.next()) {
var appService = gr.parent.getDisplayValue();
if (appService && serviceList.indexOf(appService) === -1) {
serviceList.push(appService);
}
}
return serviceList.join(', ');
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 03:29 AM
if your reference variable is referring to cmdb_ci then update as this
getRelatedServices: function() {
var serverId = this.getParameter('server_to_decomission');
if (!serverId) return '';
var serviceList = [];
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('child', serverId); // "Depends on" relationship
//gr.addQuery('type.name', 'IN', 'Depends on::, Hosted on::'); // Filter by relationship type
//gr.addQuery('parent.sys_class_name', cmdb_ci_service_auto); // Filter for app service class
gr.query();
while (gr.next()) {
var appService = gr.parent;
serviceList.push(appService.toString());
}
return serviceList.toString();
};
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