
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:15 AM
Hi,
I need help with client script. I have a form with one mandatory field, I need to make this field non mandatory for 3 users only. So if the login user / requester is one of A, B, C then this field should be non mandatory.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 01:35 PM
You might be having a UI policy which is setting the field mandatory .
UI policy precedence is higher than client script so its not working
if you are able to find the ui policy then remove ui action which makes the field mandatory and try with below script
function onLoad() {
var currentUser = g_user.user_id;
var nonMandatoryUsers = ['A', 'B', 'C']; // Replace A,B and C with the sys_ids of the users who should have the field as non-mandatory
if (nonMandatoryUsers.indexOf(currentUser)!=-1) {
g_form.setMandatory('field name', false); //replace field name with backend name of field to be made non-mandatory
}
else
{
g_form.setMandatory('field name', true);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 10:34 AM
Hi @sparkles
You can write below on load client script to do it (make changes as instructed in comments)
function onLoad() {
var currentUser = g_user.user_id;
var nonMandatoryUsers = ['A', 'B', 'C']; // Replace A,B and C with the sys_ids of the users who should have the field as non-mandatory
if (nonMandatoryUsers.indexOf(currentUser)!=-1) {
g_form.setMandatory('field name', false); //replace field name with backend name of field to be made non-mandatory
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 01:14 PM
Hi Manmohan,
Thanks for your reply, unfortunately it didn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 01:16 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 01:21 PM
function onLoad() {
//Type appropriate comment here, and begin script below
var currentUser = g_user.UserID;
var nonMandatoryUsers = ['3aaf6648db2a63c7855d90d8db9619ce', '8aaf6648db2a63c0365d90d8db9619ce', '9aaf6648db2a63c0444d90d8db9619ce'];
if (nonMandatoryUsers.indexOf(currentUser) != -1) {
g_form.setMandatory('approval_attach', false);