- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 06:01 AM
Hi All,
I need help with an ajax call parsing values.
I have a script include that works correctly and returns the list of sys ids from the same company as the requester but the CCS I am not able to parse the results. I need to limit the list of available users to be in the same company as the contact person.
Any help greatly appreciated.
CCS
SI
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 09:36 AM
You cannot set a reference qualifier with a Catalog Client Script. Well, there is a way using a Script Include to putClientData in the session, but then the reference qualifier needs changed to get the session data, so as long as you're changing the qualifier...
Assuming the two qualifiers are entirely distinct, since u_collective_identifier wasn't mentioned in your new script, the cleanest way to do this is to change the qualifier in the variable set to:
javascript:new global.getManagerUsers().getUsers(current.variables.cat_item_id, current.variables.ref_contact_person);
So we're passing in another variable value, and removing the criteria for active and collective_identifier which we will incorporate into the Script Include like you did for active on the new script. The idea for the Script Include is that the same function now includes both GlideRecords, but only runs the new one (first) if the ref_contact_person was passed in. If this variable name is not and cannot be made unique to this Catalog Item to distinguish it from the ~87 others then you can also pass in the Catalog Item sys_id using g_form.getUniqueValue(). The Script Include would now look more like this, or whatever makes sense to you knowing what each script was doing:
var getManagerUsers = Class.create();
getManagerUsers.prototype = {
initialize: function() {},
getUsers: function(cat_id, contactPersonSysId, catItemId) {
if (contactPersonSysId) { //or catItemId=..., or may re-use !isValid?...
var userList = [];
// Get the company of the contact person
var userGR = new GlideRecord('sys_user');
if (userGR.get(contactPersonSysId)) {
var contactPersonCompany = userGR.company; // Get the company of the contact person
// Query users in the same company
var gr = new GlideRecord('sys_user');
gr.addQuery('company', contactPersonCompany);
gr.addQuery('active', true); // Filter only active users
gr.query();
// Collect sys_ids of users in the same company
while (gr.next()) {
userList.push(gr.sys_id.toString()); // Add the sys_id of the user to the list
}
}
// Log the response before returning for debugging
gs.info('Returning sys_ids: ' + userList.join(',')); // Logs the array string of sys_ids
// Return the list as a JSON string
return 'sys_idIN' + userList.join(','); // Convert to array string and return it
}
var items = gs.getProperty('hidden_req_for_ref_qual_item_ids').split(','); //Store Item ids to apply ref qual
var isValid = items.indexOf(cat_id.toString()) != -1;
if (isValid) {
var tab = [];
var grUser = new GlideRecord('sys_user');
grUser.addQuery('manager', gs.getUserID());
grUser.addQuery('active', true);
grUser.addQuery('u_collective_identifier', false);
grUser.query();
while (grUser.next()) {
tab.push(grUser.getUniqueValue());
}
return "sys_idIN" + tab;
} else {
return "";
}
},
type: 'getManagerUsers'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 09:36 AM
You cannot set a reference qualifier with a Catalog Client Script. Well, there is a way using a Script Include to putClientData in the session, but then the reference qualifier needs changed to get the session data, so as long as you're changing the qualifier...
Assuming the two qualifiers are entirely distinct, since u_collective_identifier wasn't mentioned in your new script, the cleanest way to do this is to change the qualifier in the variable set to:
javascript:new global.getManagerUsers().getUsers(current.variables.cat_item_id, current.variables.ref_contact_person);
So we're passing in another variable value, and removing the criteria for active and collective_identifier which we will incorporate into the Script Include like you did for active on the new script. The idea for the Script Include is that the same function now includes both GlideRecords, but only runs the new one (first) if the ref_contact_person was passed in. If this variable name is not and cannot be made unique to this Catalog Item to distinguish it from the ~87 others then you can also pass in the Catalog Item sys_id using g_form.getUniqueValue(). The Script Include would now look more like this, or whatever makes sense to you knowing what each script was doing:
var getManagerUsers = Class.create();
getManagerUsers.prototype = {
initialize: function() {},
getUsers: function(cat_id, contactPersonSysId, catItemId) {
if (contactPersonSysId) { //or catItemId=..., or may re-use !isValid?...
var userList = [];
// Get the company of the contact person
var userGR = new GlideRecord('sys_user');
if (userGR.get(contactPersonSysId)) {
var contactPersonCompany = userGR.company; // Get the company of the contact person
// Query users in the same company
var gr = new GlideRecord('sys_user');
gr.addQuery('company', contactPersonCompany);
gr.addQuery('active', true); // Filter only active users
gr.query();
// Collect sys_ids of users in the same company
while (gr.next()) {
userList.push(gr.sys_id.toString()); // Add the sys_id of the user to the list
}
}
// Log the response before returning for debugging
gs.info('Returning sys_ids: ' + userList.join(',')); // Logs the array string of sys_ids
// Return the list as a JSON string
return 'sys_idIN' + userList.join(','); // Convert to array string and return it
}
var items = gs.getProperty('hidden_req_for_ref_qual_item_ids').split(','); //Store Item ids to apply ref qual
var isValid = items.indexOf(cat_id.toString()) != -1;
if (isValid) {
var tab = [];
var grUser = new GlideRecord('sys_user');
grUser.addQuery('manager', gs.getUserID());
grUser.addQuery('active', true);
grUser.addQuery('u_collective_identifier', false);
grUser.query();
while (grUser.next()) {
tab.push(grUser.getUniqueValue());
}
return "sys_idIN" + tab;
} else {
return "";
}
},
type: 'getManagerUsers'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 10:01 AM
I will try this and revert