Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Flow that automates adding/removing group type to a user group after Request from Catalog Item

AlexanderH23091
Tera Contributor

Hi all,

 

i need some help.  We have a catalog item for users to request if they want to add or remove group types like itil etc. The user puts the information in variables and after that i call them in the flow.

And how can i change the group type? If i select the table user group there is only a field Type. And in this field i cannot enter either the variable or the sysid of the variable.

 

Has someone a solution? Or an idea how i can automate it. It must be via Catalog Item the request.

 

Thanks

Alex

16 REPLIES 16

G Ponsekar
Tera Guru

Hi @AlexanderH23091 ,

 

You can try with below Flow Steps:
  1. Get Catalog Variables: Start your flow with the trigger from the Service Catalog and use the 'Get Catalog Variables' action to retrieve the variables from your item.
  2. Look Up the Group Record: Use the 'Look Up Record' action to find the specific user group record that needs to be modified.
    • Table: User Group [sys_user_group]
    • Condition: [Sys ID] [is] [your group_to_modify variable]
  3. Use a Flow Logic 'If' block: Drag the action_type variable into the condition to check if the user wants to "Add" or "Remove".
  4. Update the Record (Add or Remove): Place an 'Update Record' action inside both the 'If' and 'Else' blocks.
    • Record: Use the data pill from the 'Look Up Record' step [2->Group Record].
    • Fields: Select the Type field.
    • Action: Click the script icon (</>) next to the 'Type' field to open the script editor.
Inline Script for ADDING a Group Type
This script gets the current list of types, adds the new one, and returns the updated list. 
 
javascript
// Assumes you have looked up the group record in a previous step (e.g., step 2)
var currentTypes = fd_data._2__look_up_record.record.type.toString();// Get the sys_id of the type to add from your catalog variable
var typeToAdd = fd_data._1__get_catalog_variables.group_type_to_change.toString();

if (currentTypes == '') {
    return typeToAdd; // If the list is empty, just add the new type} else {
    // Combine the current list with the new type, separated by a comma
    return currentTypes + ',' + typeToAdd;
}
 
Inline Script for REMOVING a Group Type
This script converts the list to an array, removes the specified type, and converts it back to a string. 
 
javascript
// Assumes you have looked up the group record in a previous step (e.g., step 2)
var currentTypes = fd_data._2__look_up_record.record.type.toString();// Get the sys_id of the type to remove from your catalog variable
var typeToRemove = fd_data._1__get_catalog_variables.group_type_to_change.toString();

// Split the comma-separated string of sys_ids into an array
var typesArray = currentTypes.split(',');

// Find the index of the type to remove
var index = typesArray.indexOf(typeToRemove);

// If the type is found, remove it from the array
if (index > -1) {
    typesArray.splice(index, 1);
}

// Join the array back into a comma-separated string and return it
return typesArray.join(',');

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

Hi Ponsekar,

thank you for your quick response. I will try this 

I still have the problem with the type field see the attached pictures. Or maybe i got something wrong

Ah sorry i found it ok sorry, i didnt see the name property. This works