The CreatorCon Call for Content is officially open! Get started here.

Restrict Service Catalog submission for non–key users with proper message on Employee Center

adityagalan
Tera Contributor

Hi All,

I am working on a requirement where I need some help to achieve the desired behavior in Employee Center.

Requirement:

  1. All service catalogs (with key user restriction) should be visible to all end users.

  2. However, only key users (members of a specific group) should be able to submit those catalogs.

  3. If a non–key user tries to submit, they should see a message on Employee Center with a link to a report showing the allowed group members, so they understand why they cannot raise the request.

 

What I tried:

  • Created a Script Include that checks whether the currently logged-in user belongs to the key user group (using GlideRecord).

  • Created an onSubmit Client Script that calls this Script Include:

    If true → allow submission.

    If false → prevent submission and show a message.

 

Issue faced:

  • Since the Script Include is synchronous, the condition is not properly evaluated in time.

  • As a result, even if the user is not part of the key user group, they are still able to submit the request.

 

My ask:

  • What is the correct way to handle this scenario?

  • Is there any other best practice to validate group membership before submission in Employee Center?

 

Any suggestions or examples would be highly appreciated.

 

Thanks in advance!

1 ACCEPTED SOLUTION

@adityagalan 

then do this

1) have a string variable and store the flag true/false based on logged in user member of that group

javascript: gs.getUser().isMemberOf('Group ABC');

2) hide this variable always using UI policy and keep this variable at the end so that it's never seen

3) then use onSubmit script and check value of this hidden variable and stop submission

function onSubmit() {

    if (g_form.getValue('variableName').toString() == 'false') {
        alert('Not allowed to submit');
        return false;
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@adityagalan 

why not hide those catalog items itself if logged in user is not member of that group?

You can use User Criteria and add Group in that and then add this in "Available For" related list for catalog item

Apply user criteria to items and categories 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar Thanks for the suggestion. I’m aware of the User Criteria approach and it was used earlier, but in this case the requirement is to keep all catalog items visible to everyone and only restrict submission for non–key users, with a message + group users list report link for clarity. That’s why I’m exploring a submit-time validation instead of hiding the items

@Ankur Bawiskar  Thanks for the suggestion. I’m aware of the User Criteria approach and it was used earlier, but in this case the requirement is to keep all catalog items visible to everyone and only restrict submission for non–key users, with a message + group users report link for clarity. That’s why I’m exploring a submit-time validation instead of hiding the items

@adityagalan 

then do this

1) have a string variable and store the flag true/false based on logged in user member of that group

javascript: gs.getUser().isMemberOf('Group ABC');

2) hide this variable always using UI policy and keep this variable at the end so that it's never seen

3) then use onSubmit script and check value of this hidden variable and stop submission

function onSubmit() {

    if (g_form.getValue('variableName').toString() == 'false') {
        alert('Not allowed to submit');
        return false;
    }

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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