- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 11:31 PM - edited ‎04-02-2024 11:31 PM
On a field condition, if the assigned_to does not have a specific role, we'd like to clear the assigned_to value. If the assigned_to does have the role, we don't want to clear the value. This is being done through a scoped app. I've taken some suggestions from a few other posts and so far unable to achieve the goal. Currently, the value is clearing regardless of role.
Script Include
HrRoleUtils = Class.create();
HrRoleUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
hasRole: function(user, role) {
if (!user) user = this.getParameter('sysparm_user_sys_id');
if (!role) role = this.getParameter('sysparm_role');
if (user && role)
return gs.getUser().getID(user).hasRole(role);
},
type: 'HrRoleUtils'
Client Script
if (newValue == 'Yes') {
var ga = new GlideAjax('sn_hr_core.HrRoleUtils');
ga.addParam('sysparm_name', 'hasRole');
ga.addParam('sysparm_user_sys_id', g_form.getValue('assigned_to'));
ga.addParam('sysparm_role', 'sn_hr_core.u_hr_confidential');
ga.getXML(function(resp) {
var response = JSON.parse(resp.responseXML.documentElement.getAttribute('answer'));
if (response) {
g_form.clearValue('assigned_to');
}
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 01:45 AM
var HrRoleUtils = Class.create();
HrRoleUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasRole: function(userSysId, role) {
var userGr = new GlideRecord('sys_user');
if (userSysId && role) {
if (userGr.get(userSysId)) {
return gs.hasRole(role, userGr);
}
}
return false;
},
type: 'HrRoleUtils'
});
if (newValue == 'Yes') {
var assignedTo = g_form.getValue('assigned_to');
if (assignedTo) {
var ga = new GlideAjax('sn_hr_core.HrRoleUtils');
ga.addParam('sysparm_name', 'hasRole');
ga.addParam('sysparm_role', 'sn_hr_core.u_hr_confidential');
ga.addParam('sysparm_user_sys_id', assignedTo);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === 'true') {
// User has the specified role, do nothing
} else {
// User doesn't have the role, clear the assigned_to value
g_form.clearValue('assigned_to');
}
});
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 11:52 PM
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 12:04 AM - edited ‎04-03-2024 12:08 AM
This didn't work. Same results.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 12:18 AM - edited ‎04-03-2024 12:19 AM
Hi @heathers_ I can see the difference, If i pass direct sysid I get correct result which is true, check whether the variable gets sysid of the user?
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2024 02:07 AM
Hi @heathers_ the below script include works for me in PDI
Harish