- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 02:22 AM
called below script in a reference qualfier while calling passed a parameter but the value not getting pass script include function
Reference qualifier: javascript:newCIvalueretrieve().getCis(current.variables.name_of_application_service_you_want_to_map):
Script Include: var Civalueretrieve = Class.create();
initialize: function() {},
getCis: function(parentId) {
var parentIdValue "parentId;
gs.log("parentId sai testing" parentIdValue);
var relations = new GlideRecord('cmdb_rel_ci');
relations.addQuery("parent", parentIdValue);
relations.query();
var ciData [];
while (relations.next()) {
var cis new GlideRecord(cmdb_ci");
cis.addQuery("sys_id', relations.child.sys_id);
cis.query();
if (cis.next()) {
ciData.push(cis-getuniqueValue());
}
}
var strQuery new ArrayUtil().unique(ciData);
return "sys_idIN” + strQuery;
},
type: 'CIvalueretrieve
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2025 04:07 AM
then in that list collector variable you should give variable attributes so that the ref qualifier works
ref_qual_elements=name_of_application_service_you_want_to_map
add that in variable attributes
Also don't use gs.log(). use gs.info()
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-12-2025 02:36 AM
Hello @GBS
There has to be a space in between new and script include name.
Reference qualifier
javascript:new CIvalueretrieve().getCis(current.variables.name_of_application_service_you_want_to_map)
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
01-12-2025 02:41 AM
@Juhi Poddar thanks for the response. I have provided the space even though it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2025 02:50 AM
There are few syntax errors in script:
- Missing = in assignments (e.g., var parentIdValue "parentId).
- Missing " or ' around strings (e.g., cis new GlideRecord(cmdb_ci");).
- Missing = in assignments (e.g., var strQuery new ArrayUtil().unique(ciData);)
- Incorrect use of quotes in addQuery (e.g., "sys_id', relations.child.sys_id).
- Cannot pass array directly as an output, instead join them to convert it to string.
Here is the updated script include:
var CIvalueretrieve = Class.create();
CIvalueretrieve.prototype = {
initialize: function () {},
getCis: function (parentId) {
if (!parentId) {
gs.log("No parentId provided to getCis function");
return '';
}
gs.log("Parent ID passed: " + parentId);
// Query the cmdb_rel_ci table for relationships where the given ID is the parent
var relations = new GlideRecord('cmdb_rel_ci');
relations.addQuery("parent", parentId);
relations.query();
var ciData = []; // Array to store child CI sys_ids
while (relations.next()) {
// Query the cmdb_ci table for child CIs
var cis = new GlideRecord("cmdb_ci");
cis.addQuery("sys_id", relations.child.sys_id);
cis.query();
if (cis.next()) {
ciData.push(cis.getUniqueValue());
}
}
// Remove duplicate sys_ids
var uniqueCis = new ArrayUtil().unique(ciData);
// Construct the sys_idIN query
if (uniqueCis.length > 0) {
return "sys_idIN" + uniqueCis.join(",");
}
// Return an empty result if no CIs found
return '';
},
type: 'CIvalueretrieve'
};
This corrected script should resolve the issues and work as expected. Let me know if you encounter further problems!
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
01-12-2025 03:53 AM
Please share on what variable type the ref qualifier is applied
Also share what's the variable type for "name_of_application_service_you_want_to_map"?
try this
javascript: new CIvalueretrieve().getCis(current.variables.name_of_application_service_you_want_to_map);
I assume both script include and field are in same scope
var CIvalueretrieve = Class.create();
CIvalueretrieve.prototype = {
initialize: function() {},
getCis: function(parentId) {
var parentIdValue = parentId;
gs.log("parentId sai testing: " + parentIdValue);
var relations = new GlideRecord('cmdb_rel_ci');
relations.addQuery("parent", parentIdValue);
relations.query();
var ciData = [];
while (relations.next()) {
ciData.push(relations.getValue('child'));
}
var strQuery = new ArrayUtil().unique(ciData);
return "sys_idIN" + strQuery.join(",");
},
type: 'CIvalueretrieve'
};
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