Make a field not mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 05:59 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 12:17 PM
I tried the following and it is still not working. It seems when both objective and additional info is yes are in the script it won't work. Is there something wrong with what I entered:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 01:12 PM
Hey Gemma4,
First off, I believe you are putting this code in the wrong place. I'm pretty sure you want to add it to the Catalog Client Script inside the Maintain Item. That way when the user is using the request, the field will turn mandatory or not based on their role and what they select for Additional Information.
Set the default value of the Additional Information to No
Then I would create an onChange Catalog Client Script like this:
And put this in the onChange script section:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 02:12 PM
Based on what you initially wrote, it sounds like you have an approval process going on. You cannot modify the variables once they are submitted, so I'm not sure where you are putting the additional information field. Is that a field in the email that gets sent to the approving manager? The objective would already have been added in the variables by the time the manager gets the email, so setting the objective field to mandatory doesn't do anything.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 02:53 PM
Oh my, this has gotten complicated. There isn't an approval process. However, I have an order guide that uses a catalog item with all of the catalog item fields hidden on the order guide. Then I have all the additional variables displayed in the request item. If a group of managers (role PM) determines that they need additional information then that variable additional information is Yes. After Yes the rest of the variables on the RITM need to be required. I previously did a ui policy and achieved that but it was making them required for the manager selecting Yes under additional information. I'm open to feedback if there is a better way to do all this. Unfortunately it is still not working as expected, I completed your suggestions but the user with PM role is still not seeing objective as mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 08:11 AM
I tried both script below and unfortunately I'm still having issues. Instead of using the scripts and order guide and catalog item is there a different approach I should have used for the process required?
Both scripts produce different results.
- This script below is :
Allows user with role PM to select Yes at additional fields
Objective is Not required for the user that selected Yes
The above is perfect
The problem is user without PM role should then be able to go in RITM and variable objective is required. The objective variable is not required even if I refresh or try to select it again.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return; // Return if nothing changed
}
// Check to see if the user has the "pm" role and grab the additional information field value
var hasPMRole = g_user.hasRole('pm');
var ynAddtnlInfo = g_form.getValue('additional_information');
// Get the GlideFormElement object of the "objectives" field
var objectivesField = g_form.getField('objectives');
// If the user selects "yes" and they have the "pm" role, then make the "objectives" field mandatory
if (ynAddtnlInfo === 'yes' && hasPMRole) {
objectivesField.setMandatory(true);
} else {
// Otherwise, don't make it mandatory
objectivesField.setMandatory(false);
}
}
My original script above and below is having a different issue also
A user with role PM can select Yes at additional fields
Objective is then required for the user that selected Yes
The above is a problem because the user that selects Yes at additional information is simply responsible for deterring if additional information is required. A second user without the role PM needs to complete the required fields. The second user that accesses the RITM does not view objective as required. The only way the 2nd user can view it as required is if they select additional information no and then change it to yes.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return; //return if nothing changed
}
//Check to see if user has pm role and grab the additional information field value
var role = g_user.hasRole('pm');
var ynAddtnlInfo = g_form.getValue('additional_information');
//if the user selects yes and they have the pm role, then make the objectives field mandatory
if (ynAddtnlInfo == 'Yes') {
if( role == true) {
g_form.setMandatory('objectives',true);
}
else { //they don't have the pm role, so make it not mandatory
g_form.setMandatory('objectives',false);
}
}
else { //they selected no, so don't make it mandatory
g_form.setMandatory('objectives',false);
}
}