onload client script

sparkles
Tera Contributor

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! 

1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

@sparkles 

 

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);  
}
}

 

View solution in original post

6 REPLIES 6

Manmohan K
Tera Sage

@sparkles 

 

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);  
}
}

 

Hi Manmohan,

 

I don't have any UI policy that setting the field mandatory . However, when I changed the "!=1" to ">0" it works. Thanks again for your help!