- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:16 AM
Hello,
Any assistance is appreciated.
I have a cat item which has the following
1. Reference Variable pointing to cmdb_ci_business_app table. 2. Once I make a selection from 1 then a lookup selectbox filters values from cmdb_rel_ci see below.
3. There is a reference variable to the user table which they would populate with the child.owned_by when 2 is selected. I tried below but it is not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 05:55 PM
Here is the corrected Script Include, with some temporary log lines, so if you are still not getting the expected results you can share which system logs you are seeing (filter on Message starts with SI)
var Cloud_Owned_by = Class.create();
Cloud_Owned_by.prototype = Object.extendsObject(AbstractAjaxProcessor, {
updateOwned: function () {
var results = 'none';
var buildingid = this.getParameter('sysparm_application_service');
gs.info('SI running: buildingid = ' + buildingid);
var loc = new GlideRecord('cmdb_ci');
loc.addQuery('sys_id', buildingid);
loc.query();
if (loc.next()) {
gs.info('SI record found: ' + loc.name);
results = {
"owned_by": loc.getValue('owned_by'),
"managed_by": loc.getValue('managed_by')
};
gs.info('SI results: ' + JSON.stringify(results));
return JSON.stringify(results);
} else {
return results;
}
},
type: 'Cloud_Owned_by'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:34 AM
To be clear, the reference qualifier for 3. will limit the records that can be selected, not populate the value of the variable. In the qualifier, you need a field on the user table to go with the variable.owned_by, and then you need an AND character (^) before the active, so maybe you're looking for something more like:
javascriptt: 'sys_id=' + current.variables.select_your_application_service_environment.owned_by + '^active=true^internal_integration_user=false';
of course with just one t in javascript. If you want to actually populate the variable with this value, clear the reference qualifier and add an onChange Catalog Client Script when 2. changes. This script would use GlideAjax to call a Script Include, passing in the newValue. The Script Include will query the cmdb_ci table for the sys_id passed in from the client, returning the value of the owned_by for the client script to populate in the reference variable. Your Lookup Value Field on 2 should be Child instead of Parent.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 12:50 PM
Hello,
Yes I would like to be set from the child when selected. I also need to set Managed By variable so I would assume we can set both in the same call. Any assistance is appreciated. Thanks Brad.
Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 01:39 PM
Sure - add a comma to the end of line 8, then a similar format for loc.managed_by. Consider changing line 13 to return 'false'; or something unique so when troubleshooting the response from the server you'll know that the script ran.
On the GlideRecord, if you are passing in the application_service parameter which contains the sys_id of the (child) CI, you'll want it to look like this:
var loc = new GlideRecord('cmdb_ci');
loc.addQuery('sys_id', buildingid);
loc.query();
if (loc.next()) {
var results = {
"owned_by": loc.getValue('owned_by'),
"maanged_by": loc.getValue('managed_by')
};
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 04:02 PM
Hello,
Unfortunately does not work. Thanks.
Client Script