Make a field not mandatory

Gemma4
Mega Sage

Hi Everyone,

I have a requirement to make fields mandatory on the ritm level but only mandatory for a group of users completing the form? Below are the details of the process

The variables are hidden on the catalog item. 

If the manager determines additional information is needed then the variables are required by a yes/no ui policy

The problem is the manager doesn't need to complete the form, so I need to exclude her and others from seeing them as required. 

I realize the best way to achieve this is probably with a UIPolicy but I'm struggling on how to exclude the manager/group from seeing the variables as required. 

Below is the script I have so far but not sure if there is a better way to do this or if its possible?

 

function onSubmit() {

 

    //Type appropriate comment here, and begin script below

 

    g_form.setMandatory('field_name',false);

 

}

 

Thanks so much for any feedback you have!

27 REPLIES 27

Hi @POOJA SINGH18 

I'm not sure I understand your suggestion. I attempted the solution by @Samaksh Wani  but unfortunately the variables are now required for everyone; regardless of group and it should only be required for the  group members if the variable additional information is yes. I'm not very good with scripting and not familiar with Ajax call. Can I get your help further? 

 

Gemma4
Mega Sage

I also tried the following client script and now objectives is not required at all..😢

 

//SECOND ATTEMP
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('group.name', 'ProjectManagement');
grp.addQuery('user', userID);
grp.query(groupMemberCallback);
 
function groupMemberCallback(grp){
//If user is a member of selected group
if(grp.next()){
 
g_form.setMandatory('objectives',true);
}
else {
if (role == false)
{
g_form.setMandatory('objectives',false);
}
else
{
g_form.setMandatory('objectives',true);
}
}
}
}

Gemma4
Mega Sage

Good news I got the script to almost work and just need a tiny bit more help. Below is the onload client script I used and when a member of service desk is selected the objective variable is not required. However when a member of Project management with Role PM the objective variable is required. That part is great.

My last questions is, the variable objective should only be required for the role PM if..

variable additional information = yes

Can I get help adding that last part??

 

 

function onLoad() {
var role = g_user.hasRole('pm');
 
if( role == true)
{
g_form.setMandatory('objectives',true);
 
}
else
{
g_form.setMandatory('objectives',false);
 
}
}

Hello @Gemma4 

 

function onLoad() {
var role = g_user.hasRole('pm');
var info =g_form.getValue('additional_information');
 
if( role == true)
{

if(info=='yes'){
g_form.setMandatory('objectives',true);
}
else{
g_form.setMandatory('objectives',false)
}

}
else
{
g_form.setMandatory('objectives',false);
 
}
}

 

Here is your additional script

 

 

Try this:

var ynAddtnlInfo = g_form.getValue('<additional info variable name');

if (ynAddtnlInfo == 'yes'); {

//do the "yes" part of it

}

else {

//do the "no" part of it

}