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

Hey Gemma4, 

 

I think the issue with the first script is here:

if (ynAddtnlInfo === 'yes' && hasPMRole)

The yes needs to be Yes.

Put a g_form.addInfoMessage("Addtnl Info: " + ynAddtnlInfo); before the if statement to see what the value is. Is it "yes" or "Yes". Case sensitive.

Catalog Client Script should look like this:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var role = g_user.hasRole('pm');
	var ynAddtnlInfo = g_form.getValue('additional_information');
 
 g_form.addInfoMessage("Addtnl Info value: " + ynAddtnlInfo);
 g_form.addInfoMessage("Has pm role: " + role);
 
	if (ynAddtnlInfo == 'Yes' && role == true) {
		g_form.setMandatory('objectives',true);
	}
	else {
		g_form.setMandatory('objectives',false);
	}   
}

When you're done testing, either comment out the two messages or remove them.

Hey @cgedney

I tried the script you shared and it is slightly different and I'm getting a missing function declaration on load error now. I already attempted to change "yes" to Yes but that didn't make a difference. Any ideas?

 

missing function declaration.png

 

Missing function declaration for onLoad

This script is for an onChange function, not onLoad. You'd have to change it to onChange.

 

Basically, what you want it to do is trigger when the user changes the additional_information field.

 

Just curious, can I get feedback on the workaround I tested successfully? Just want to know if you forsee any issues.

 

I did come up with a workaround but I'm not sure it would be ok. If we can add an additional field on the catalog item that if answered yes then it will trigger the rest of the variables to be required. Created a ui policy
To test this in dev I added  "Did you collaborate with Executive Sponsor or Business Owner to complete." We can rename that to anything. 
If yes is added the additional variables are required.

Catalog UI Policy would do the same thing. The only piece that might need a little work is the role="pm". You'd have to write script to test for that. Otherwise, the Catalog UI Policy should work nicely.

 

Maybe add this to the "Execute if true": 

    var role = g_user.hasRole('pm');
    return role;