help with script, please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 08:42 PM
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 someon in the group project management (pm role) determines additional information is needed then the additional variables are required by a yes/no ui policy
The problem is the manager doesn't need to complete the form with the required fields. An email is triggered to the group that needs to complete it. So I need to exclude her and others from seeing them 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? Currently the variable objective is not becoming mandatory when additional information is selected.
thanks in advance for any feedback you have.
onChange script section:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:24 AM
Hi @Gemma4 ,
Try with below updated script:
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);
}
}
Thanks,
Ratnakar