- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 03:49 PM
Requirement: The change request form has cmdb_ci field and an out of box business_service field, which I have brought on the form. On selecting any CI from the lookup of cmdb_ci field, the business service lookup should fetch the parents of the currently displayed CI on the form, uptill 4 levels.
My approach: I have written a script include function, which takes in the sysid of cmdb_ci as the parameter and returns the parents sysid's. This is working fine in the background script.
Table: cmdb_rel_ci - for script include which fetches the parent of current CI.
I am stuck here: How to get the current cmdb_ci sysid sent to the script include via reference qualifier on business_service dictionary, so the function can do its job. Also, how the returned sysds should be sent so that the business_service lookup displays the records of the corresponding sysids?
Can someone help me on this please?
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 04:02 PM
I just answered a question similar to this for a reference qualifier for group members so here's an example...
You can use an advanced reference qualifier on your field. First you'll need to set up your script include with an on demand function. What that means is that you'll need a script include with a name that exactly matches the function name you want to call. In my group member example, it was named 'u_getGroupMembers'. It takes in a single parameter (the sys_id of a group that came from the 'assignment_group' field. In your scenario this is where you would pass in the value of the 'cmdb_ci' field. The script looked like this...
function u_getGroupMembers(groupId) {
if (gs.nil(groupId))
return;
var memberIds = [];
var members = new GlideRecord('sys_user_grmember');
members.addQuery('group', groupId);
members.addQuery('user.active', true);
members.query();
while(members.next()) {
memberIds.push(members.getValue('user'));
}
return "sys_idIN" + memberIds.join();
}
The key is right at the end. You need to return an encoded query string that lists the items you want to show in the reference field. The encoded query string needs to look like this...
'sys_idINBUSINESS_SERVICE_SYS_ID_1,BUSINESS_SERVICE_SYS_ID_2,BUSINESS_SERVICE_SYS_ID_3, ETC...
Then you need to set your 'Reference qualifier' field on the dictionary entry of the Business service field. Where it says 'YOUR_GROUP_FIELD_OR_VARIABLE_NAME_HERE', change that to the name of your ci field. Obviously, you'll also change your function name to call the function you set up in your script include.
javascript: u_getGroupMembers(current.YOUR_GROUP_FIELD_OR_VARIABLE_NAME_HERE);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 04:02 PM
I just answered a question similar to this for a reference qualifier for group members so here's an example...
You can use an advanced reference qualifier on your field. First you'll need to set up your script include with an on demand function. What that means is that you'll need a script include with a name that exactly matches the function name you want to call. In my group member example, it was named 'u_getGroupMembers'. It takes in a single parameter (the sys_id of a group that came from the 'assignment_group' field. In your scenario this is where you would pass in the value of the 'cmdb_ci' field. The script looked like this...
function u_getGroupMembers(groupId) {
if (gs.nil(groupId))
return;
var memberIds = [];
var members = new GlideRecord('sys_user_grmember');
members.addQuery('group', groupId);
members.addQuery('user.active', true);
members.query();
while(members.next()) {
memberIds.push(members.getValue('user'));
}
return "sys_idIN" + memberIds.join();
}
The key is right at the end. You need to return an encoded query string that lists the items you want to show in the reference field. The encoded query string needs to look like this...
'sys_idINBUSINESS_SERVICE_SYS_ID_1,BUSINESS_SERVICE_SYS_ID_2,BUSINESS_SERVICE_SYS_ID_3, ETC...
Then you need to set your 'Reference qualifier' field on the dictionary entry of the Business service field. Where it says 'YOUR_GROUP_FIELD_OR_VARIABLE_NAME_HERE', change that to the name of your ci field. Obviously, you'll also change your function name to call the function you set up in your script include.
javascript: u_getGroupMembers(current.YOUR_GROUP_FIELD_OR_VARIABLE_NAME_HERE);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 04:25 PM
Hi Mark,
Did as you said. The logs shows an error which reads like this:
Script: GeolocationAJAX not found in scope: global, and HTTP Processor class not found: com.glide.processors.xmlhttp.GeolocationAJAX: no thrown error
Looks like the sys_id of cmdb_ci field is not getting passed to the script properly cz the debug message just doesn't show up in the logs.
Reference : Advanced
Table: CI Relationship
Reference Qualifier: javascript: bringSysIds(current.cmdb_ci);
Script Include: bringSysIds
Function Name: bringSysIds: function(id){
// code here
}
Thanks!
Script Include's are attached...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 04:41 PM
Thanks Mark! I changed the table to cmdb_ci_service in the Reference for the business_service field. It worked!
Thanks again.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2018 05:22 PM
Awesome! Your script include was the hardest part, but I'm glad we could put the pieces together. This is a good technique to know how to do, you'll use it all the time.