Exclude Cat Item Variable Value

purdue
Kilo Sage

Hello,

We have a cat item where the end user can request assignment groups be updated.  See screenshot below  The user can select new group name and the group manager and optional group membership.  Once approved the following function is ran.

updateExistingGroup: function(variables) {
var gGroup = new GlideRecord('sys_user_group');
if (gGroup.get(variables.which_assignment_group_needs_to_be_changed.toString())) {
gGroup.setValue('name', variables.group_name);
gGroup.setValue('description', variables.new_group_description);
gGroup.setValue('manager', variables.new_manager);
gGroup.setValue('email', variables.new_email);
gGroup.setValue('type', variables.group_type.toString());
gGroup.update();

We have a defect where if 2 different request are submitted.   1. for changing the group manager and 2. for updating the group members, then if the group manager request is approved first then the manager is updated to the value the user selected.  However once the second is approved for the group membership it overwrites the first request because current and new group manager is defaulted to the existing manager at the time the request was submitted.   So I need to update the SI to only allow group manager update if New Manager does not equal Current Manger.   I thought about doing a gr on Variable Ownership then compare values of the 2 variables but not sure how.  Perhaps there is a better way to do this.   Any help is welcome.

Screenshot 2025-04-29 at 11.11.23 PM.png

 
 
1 ACCEPTED SOLUTION

Nick Parsons
Mega Sage

You can add an if-statement to check that they're different values and only update it if it's changing:

 // if a different manager was selected on the form, then update the manager field, otherwise don't set the manager field
if(variables.new_manager != variables.current_manager) {
  gGroup.setValue('manager', variables.new_manager);
}

View solution in original post

4 REPLIES 4

J Siva
Tera Sage

Hi @purdue 
In the past, I encountered a similar requirement. To address this, we introduced new checkbox variables with options such as 'Update manager' and 'Update group members.' End users need to select the appropriate checkboxes. The flow/script then validates the checkbox values and updates the group record accordingly.

Hope this helps.
Regards,
Siva

Thanks for the response.   I did not want to update the cat item but I agree I would have a Select Box with values of what the user wants to do.

Nick Parsons
Mega Sage

You can add an if-statement to check that they're different values and only update it if it's changing:

 // if a different manager was selected on the form, then update the manager field, otherwise don't set the manager field
if(variables.new_manager != variables.current_manager) {
  gGroup.setValue('manager', variables.new_manager);
}

purdue
Kilo Sage

Thanks Nick this worked.   I don't why I overcomplicate things. 😀