- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi all,
My requirement is if the logged in users Hr profile's isManager is false and the job profile.job family groups(Reference field) is Accounting. then I want to remove an option in the record producer. I tried but I am getting no where
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Abishek1998
Try with this:
1: Create a Script Include
- Navigate to System Definition > Script Includes > click New.
- Name it: checkUserJobDetails
- Check the Client callable box.
var checkUserJobDetails = Class.create();
checkUserJobDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = gs.getUserID();
var result = {
isManager: false,
isAccounting: false
};
var hrGr = new GlideRecord('sn_hr_core_profile');
hrGr.addQuery('user', userId);
hrGr.query();
if (hrGr.next()) {
result.isManager = hrGr.getValue('is_manager') == 'true';
var jobGr = hrGr.job_profile.getRefRecord();
if (jobGr.isValid()) {
var jobFamilyGroup = jobGr.job_family_groups.getDisplayValue();
if (jobFamilyGroup == 'Accounting') {
result.isAccounting = true;
}
}
}
return JSON.stringify(result);
},
type: 'checkUserJobDetails'
});
2: Create a Catalog Client Script
- Navigate to Service Catalog > Catalog Administration > Catalog Client Scripts > click New.
- Name: Hide Option for Non-Manager Accountants
- Applies to: A Record Producer
- Record Producer: Select your specific record producer
- UI Type: All
- Type: onLoad
function onLoad() {
var ga = new GlideAjax('checkUserJobDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.getXMLAnswer(function(response) {
if (response) {
var userDetails = JSON.parse(response);
if (userDetails.isAccounting && !userDetails.isManager) {
g_form.removeOption('variable_name', 'option_value'); //update variable_name, option_value with your actual value
}
}
});
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Abishek1998
Try with this:
1: Create a Script Include
- Navigate to System Definition > Script Includes > click New.
- Name it: checkUserJobDetails
- Check the Client callable box.
var checkUserJobDetails = Class.create();
checkUserJobDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userId = gs.getUserID();
var result = {
isManager: false,
isAccounting: false
};
var hrGr = new GlideRecord('sn_hr_core_profile');
hrGr.addQuery('user', userId);
hrGr.query();
if (hrGr.next()) {
result.isManager = hrGr.getValue('is_manager') == 'true';
var jobGr = hrGr.job_profile.getRefRecord();
if (jobGr.isValid()) {
var jobFamilyGroup = jobGr.job_family_groups.getDisplayValue();
if (jobFamilyGroup == 'Accounting') {
result.isAccounting = true;
}
}
}
return JSON.stringify(result);
},
type: 'checkUserJobDetails'
});
2: Create a Catalog Client Script
- Navigate to Service Catalog > Catalog Administration > Catalog Client Scripts > click New.
- Name: Hide Option for Non-Manager Accountants
- Applies to: A Record Producer
- Record Producer: Select your specific record producer
- UI Type: All
- Type: onLoad
function onLoad() {
var ga = new GlideAjax('checkUserJobDetails');
ga.addParam('sysparm_name', 'getUserDetails');
ga.getXMLAnswer(function(response) {
if (response) {
var userDetails = JSON.parse(response);
if (userDetails.isAccounting && !userDetails.isManager) {
g_form.removeOption('variable_name', 'option_value'); //update variable_name, option_value with your actual value
}
}
});
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti