how to make field mandatory for particular role,or users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-28-2022 06:16 AM
hii all,
my requirement is
in the company table, employee field is non-mandatory only for the program manager.
how to make this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-28-2022 06:21 AM
You have to functions which you can use:
gs.getUserID() // this will give you the sys_id of the logged in user to compare
gs.hasRole('itil')// this will return true or false if user has itil role or not for logged in user
Using these conditions you can check in onload client script to handle such aspects to make a field mandatory or read only or visible.
Ex:
if(gs.hasRole('itil')){
g_form.setMandatory("priority",true);
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions š
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-28-2022 06:21 AM
Hope Program Manager is title or role of the user.
You can create a Client Script and check whether current user is program manager. Set the field mandatory if true.
Thank you,
Palani
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-28-2022 07:41 AM
can you help me with the script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-01-2022 02:38 AM
You can use the script. This is based on assumption that title field in user record has Program Manager to differentiate whether user is program manager or not.
Refer the inline comments to make any changes
function onLoad() {
var user_ajax = new GlideAjax('RecordFieldGetter');
user_ajax.addParam('sysparm_name', 'getValue');
user_ajax.addParam('sysparm_table', 'sys_user');
user_ajax.addParam('sysparm_sys_id', g_user.userID);
user_ajax.addParam('sysparm_field_name', 'title'); // Update title to actual field that has the user title
user_ajax.getXML(returnAnswer);
}
function returnAnswer(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer.toLowerCase() == 'program manager'){ // Replace program manager with actual name used in table
g_form.setMandatory('name',false); // replace name with actual field name for employee number
}
else{
g_form.setMandatory('name',true); // replace name with actual field name for employee number
}
}
Palani