Script to check if logged in user not the same as requested for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 01:11 PM - edited 04-28-2024 01:18 PM
Hi,
I want script to check if "logged-in user" is not the same as requested for user then display the category that "logged-in user" eligible for and the "requested for" as well. Currently it display whatever is the "requested for" is eligible for
The client script I have:
var ABCD_RequestUtils= Class.create();
ABCD_RequestUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// Getting Group name by send group type
getGroupsByCategory: function(category) {
var groupTypeName = '';
var groupTypeObj = new GlideRecord("sys_user_group_type");
groupTypeObj.addQuery("name", category);
groupTypeObj.query();
if (groupTypeObj.next()) {
groupTypeName = groupTypeObj.sys_id.toString();
}
var groupArr = [];
var group = new GlideRecord("sys_user_group");
group.addQuery("type", groupTypeName);
group.query();
while (group.next()) {
groupArr.push(group.sys_id.toString());
}
return groupArr;
},
getuserdetailsbyuserid: function() {
var userdetail;
var access = false;
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", gs.getUserID());
user.query();
if (user.next()) {
userdetail = user.title;
}
if ((userdetail.toString().indexOf('Manager') >= 0) || (userdetail.toString().indexOf('Director') >= 0) || (userdetail.toString().indexOf('Partner') >= 0)) {
access = true;
}
//Checking for non-management/designated folks who can view the request form
var designatedUsers = gs.getProperty('req_designated_users');
if (designatedUsers.indexOf(gs.getUserName()) != -1)
access = true;
return access;
},
// Getting Approver name by send group
getGroupByDetails: function() {
var groupDetails = {};
groupDetails.approver = '';
groupDetails.klw = 'false';
//var details = [];
var groupname = this.getParameter('sysparm_group');
var group = new GlideRecord("sys_user_group");
group.addQuery("sys_id", groupname);
group.query();
if (group.next()) {
groupDetails.approver = group.u_owner.toString();
if ((group.type.getDisplayValue().toString().indexOf('test1') >= 0)) {
groupDetails.klw = 'true';
}
}
return JSON.stringify(groupDetails);
},
limitCategories: function() {
var userCostCenter = '';
var categoryObj = {};
var userId = this.getParameter('sysparm_userid');
var user = new GlideRecord("sys_user");
user.addQuery("sys_id",userId);
user.query();
if (user.next()) {
userCostCenter = user.department.id.toString();
}
//Creating a flag for each category (Rik, Mrk, etc...)
categoryObj.showRik = this._user_from_rik_cost_centre(userCostCenter);
categoryObj.showMrk = 'true';
categoryObj.showEng = 'true';
categoryObj.showRept = 'true';
categoryObj.showFin = this._user_from_finance_cost_centre(userCostCenter);
categoryObj.showBilling = this._user_from_billing_cost_centre(userCostCenter);
return JSON.stringify(categoryObj);
},
_user_from_rik_cost_centre: function(userCostCenter) {
var result = 'false';
if (userCostCenter == '12345')
result = 'true';
return result;
},
_user_from_finance_cost_centre: function(userCostCenter) {
var result = 'false';
var financeCostCenterList = '28110123,28110125,28110126,28110127,28110129,28110130,28110131,28110132,28110133,28110134,28110135,28110393,28110396';
if (financeCostCenterList.split(',').indexOf(userCostCenter) != -1)
result = 'true';
return result;
},
_user_from_billing_cost_centre: function(userCostCenter) {
var result = 'false';
var billingCostCenterList = '28110353,28110354,28110355,28110356';
if (billingCostCenterList.split(',').indexOf(userCostCenter) != -1)
result = 'true';
return result;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 01:15 PM
Try:
var ga = new GlideAjax('ABCD_RequestUtils');
in your client script is you want to access the script include you have posted. as:
var ga = new GlideAjax('script include');
won't do anything unless you have a script include named 'script include'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 01:17 PM
Sorry, its the same name but I changed it here (for privacy) without noticing I used different name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 03:30 PM
Hi @sparkles,
Sorry, I am not sure what the issue is.
You have stated that Script to check if logged in user not the same as requested for as the name of the question but you are showing some scripts to modify the list of choice via AJAX.
Are you having an issue populating the choice list or something else?
Cheers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 04:35 AM
Hi James,
Thanks for your reply! The way the request works is the category display options based on the login user's cost center. What I want if the logged-in user one of the approver and wants to submit request for someone else, the category to display options based on the logged-in cost center and the "requested for" cost center.
I have a variable (hidden) for the approver
Thanks!