- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 06:34 AM
Hi All,
I have an advanced ref qualifier and I am calling a SI
Javascript:new NewIPC().getIPCServersForCurrentUser(current.variables.req_for);
In my SI I am not sure how to receive or map the var req_for. I am only trying this because in my AJAX call it return the expected values but also other record form the CMDB_CI and I am not quite sure why.
Any input appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 06:17 AM
I missed earlier that it looks like you are capitalizing the J. It's hard to tell with this editor substitutions, but it should look like this:
Confirm the reference table for this variable is cmdb_ci_server, and that have a variable named req_for that is a reference to sys_user, then you should see the selected user sys_id logged in the Script Include. If the logic in the SI is correct, you should see the correct records logged before the return, then the same should show in the list on the reference variable. None of this is using or requires AJAX or a Catalog Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 09:25 AM
I made that change and in log or console I see the correct CIs logged but in the field itself I see all CIs that are ipc true
I suspect it is this return ciList.join(','); // Return comma-separated sys_ids of the servers and g_form.setValue('ipc_server', sysIds[0]); // Set the first sys_id as the value
so I changed the SI to return 'sys_idIN' +ciList; but to no avail I still see far to many CIs
Any suggestion I should return and set it on the variable to only show the valid CIs and also I don't want it to set the field at all so not sure how to stop it set the variable, at least it sets it to a valid CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 09:36 AM
Inactive the Catalog Client Script, and any others you might have running onLoad or onChange to take that out of the equation, then the list of records should be the same as the logged ciList. If you don't need to do anything else, leave it inactivated. If you still want it to clear any value onLoad if no records are returned, but that's all, then just comment out/remove the setValue line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 04:57 AM
Hi Brad,
I tried the above but didn't work either.
In my PDI I created a small cat item I am on Xanadu
I logs the correct user sys id, comp sys id and logs the 4 servers the user should see but in the variable all server are listed. I do not understand this at all anymore. The ref variable for ipc_server I tried simple and advanced with and without ref qualifier does this matter?
I have done quite a few of these AJAX calls and they always return the expected values so I am baffled and cannot figure out how to solve this.
SI
var Icptest = Class.create();
Icptest.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getIPCServersForCurrentUser: function() {
var req_for = this.getParameter('sysparm_req_for'); // Get the passed req_for user sys_id
if (!req_for) {
gs.warn('No req_for value passed to Script Include.');
return '';
}
gs.info('Starting getIPCServersForCurrentUser for user: ' + req_for); // Log user sys_id
var result = [];
// Get the company of the current user
var userGR = new GlideRecord('sys_user');
if (userGR.get(req_for)) {
var userCompanySysId = userGR.company.sys_id.toString(); // Get user's company sys_id
gs.info('User found: ' + req_for + ', Company: ' + userCompanySysId); // Log user's company
// Query cmdb_ci_server for servers where u_ipc is true and company matches
var serverGR = new GlideRecord('cmdb_ci_server');
serverGR.addQuery('u_ipc', true); // Only IPC servers
serverGR.addQuery('company', userCompanySysId); // Match user's company sys_id
serverGR.query();
// Collect the sys_ids of the matching records
gs.info('Querying cmdb_ci_server for IPC servers in company: ' + userCompanySysId);
while (serverGR.next()) {
gs.info('Found IPC server: ' + serverGR.getValue('sys_id')); // Log each matching sys_id
result.push(serverGR.getValue('sys_id'));
}
} else {
gs.warn('User not found for sys_id: ' + req_for); // Log if the user is not found
}
gs.info('Returning IPC server sys_ids: ' + result.join(',')); // Log final result
return result.join(','); // Return comma-separated sys_ids
},
type: 'Icptest'
});
AJAX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 05:07 AM
I'm not understanding why you are doing a CCS/AJAX. THE way to control the records that are displayed in a reference variable on a Catalog Item / RITM / Catalog Task form, is to use a reference qualifier. In your case you need to use an advanced one that calls a Script Include. Start with only that to get the correct records in the list before trying to do anything with a catalog client script or ajax call. Use the advanced reference qualifier and script include version with req_for passed in from the reference qualifier that I proposed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2024 06:04 AM
I am sorry to be so troublesome but I tried it with ref qual as below
Javascript:'sys_idIN' + new NewIPC().getIPCServersForCurrentUser(current.variables.req_for);
and AJAX call as you suggested but either way I see all servers so not sure how to solve this now. so that it will only show the servers ipc true for the requesters company.