- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 03:01 AM
Hi all,
I have a requirement on a Catalog Item to populate a field based on a prior selection. I have written a script but cannot get it to function, details below:
Variable name: 'server_to_enable' - this populates a list of configuration items.
Variable name: 'environment_to_enable' - we want this to populate with a list of environments that are associated with the earlier configuration items field. (this is the field that is not populating).
I've attached the script below, thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 03:21 AM
Hello Ankur,
Thanks for the script details. I tested this out but it did not work unfortunately. I believe the script includes method may be the way forward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 07:38 PM
2 approaches
1) onChange + GlideAjax script include
OR
2) onChange + GlideRecord callback
try this 2nd approach I shared
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var vServer = g_form.getValue('server_to_enable');
var gr = new GlideRecord("cmdb_ci_rel");
gr.addQuery("child", vServer);
gr.addQuery("parent.sys_class_name", "cmdb_ci_environment");
gr.query(checkRecord);
function checkRecord(gr) {
if (gr.next()) {
if (gr.parent)
g_form.setValue('environment_to_enable', parent);
}
}
}
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
01-22-2025 03:21 AM
Hello Ankur,
Thanks for the script details. I tested this out but it did not work unfortunately. I believe the script includes method may be the way forward.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 03:51 AM - edited 01-22-2025 03:52 AM
it should work now
1) the table name is cmdb_rel_ci and not cmdb_ci_rel
2) also I was giving wrong value during setValue()
Updated script below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var vServer = g_form.getValue('server_to_enable');
var gr = new GlideRecord("cmdb_rel_ci");
gr.addQuery("child", vServer);
gr.addQuery("parent.sys_class_name", "cmdb_ci_environment");
gr.query(checkRecord);
function checkRecord(gr) {
if (gr.next()) {
if (gr.parent)
g_form.setValue('environment_to_enable', gr.parent);
}
}
}
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
01-27-2025 02:53 AM
Hi Ankur,
Thanks for the updated script. I tested without success unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2025 03:05 AM
Hello @GMoon
Did you tried to see what value is coming up by putting some alert statements.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.