Help assigning a role to all users simultaneously with script.

Gemma4
Mega Sage

Hi everyone,

I have a role that is used in a catalog item and I need to grant all users access to this role; so everyone in the company can access this catalog item. (the role determines when variables are required and only users with the pm manager role will not have the variables required.

Can someone help me with a script to grant all users access to this pm_user role? 

Thanks so much!

 

 

8 REPLIES 8

thank you @Sandeep Rajput for the clarification. The problem I'm having is when I remove the role from my ui policy script then the variables are required before the user can submit the request and even for the manager. I need those variables only required after the request has been submitted and after additional information is yes and they should never be required for users with pm role. Users with the pm role are the managers and they are responsible for deciding if yes additional information is selected. I'm open to not giving everyone the role as I do agree with you and I'm open to rearranging my script but everything I've tried isn't working. Attached is the script in case you have an idea that may help. thanks again for all the feedback and wisdom!

Ankur Bawiskar
Tera Patron
Tera Patron

@Gemma4 

So what all information is present in that catalog item i.e. variables on form?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

Correct the catalog ui policy contains variables. A little history that may help. 

I have a catalog ui policy script that was working perfectly today and then got a new requirement. The previous requirement was that if a variable additional information was yes (after the initial submition of the request) then any user with role pm_user would be required to answer additional required variables after the initial submit of the request. Attached is a copy of the script and when to apply.

Today I was asked to still follow all the requirements above, but to make the variables required for ALL users and not just those with the role. I've tried many variations in my script to remove the role or add not but nothing is working. 

 

As a result, since I know my script is working 100% perfectly below, I thought it may be best to simply give all users the pm_user role to ensure my process continues to work. Hope that helps clarify things. I'm open to ideas if there is a better approach than scripting. I wasn't sure if it would be best to create a group, add the pm_user role to a group and then add all the users to the group. However again I wasn't sure best approach to add all the users to the group so it isn't manual. 

thanks

 

scriptwhen.PNGscriptgj.PNG

Riya Verma
Kilo Sage
Kilo Sage

Hi @Gemma4 ,

 

Hope you are doing great. 

 

 

Certainly, to grant all users access to the "pm_user" role in ServiceNow, 

  1. Log in to your ServiceNow instance as an administrator.

  2. Navigate to "User Administration" > "Users."

  3. Use a filter to list all users (you may need to adjust the filter criteria to include all users in your company).

  4. Select all the listed users.

  5. Click on "Actions" and choose "Add Roles."

  6. In the "Add Roles" dialog, type "pm_user" (the name of the role you want to grant) and select it from the suggestions.

  7. Click "Add" to assign the "pm_user" role to all selected users.

Now, all users in your company will have access to the "pm_user" role, which should grant them access to the catalog item as per your requirements.

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma