Restrict user to submit form (via onSubmit Client script)

Elena Pomana
Tera Guru

Hello,

 

My requirement is to restrict submit option if a user is part of a certain group.

The user needs to access the catalog item and should be able to see all the variables in it (which are set to read only) but if submit button is clicked, an error should appear and the submission shouldn't be allowed.

 

Things I have tried:

Script include:

ElenaPomana_0-1676475061160.png

Client script onSubmit:

1st version:

ElenaPomana_2-1676475099136.png

2nd version:

ElenaPomana_3-1676475179119.png

I have tried with XMLWait as well but the method is no longer used.

 

Thank you.

Elena

1 ACCEPTED SOLUTION

Let me know what do you guys think, I managed to solve it this way:

Script include:

ElenaPomana_0-1676539602212.png

Client script:

ElenaPomana_1-1676539642248.png

Tested it both ways(user part of group, user that isn't part of the group) and it seems that it works as expected.

 

Thank you for all the ideas, you guys are amazing!

 

Have a great day,

Elena

 

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hi,

You may need to pass the user information to your script include as an additional Param (i.e., g_user class). Then do a query against group member table looking at specific groups to get your result. Unsure if from the client and GlideAjax if it sends it over automatically and then your use of GlideSystem User Objects would pick it up. Have you added any log statements to your script include to see what your grp is getting set as? And in your client script, as an alert (for example), what you're getting for response/answer?


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen,

 

Yes. I had logs everywhere. 

Server side logic worked good, my logs showed if the impersonated user is/isn't part of that group and my client side logic received either "true" or "false" (this is what that grp returned).

I've changed the logic as you said but the form still gets submitted:
Client script:

ElenaPomana_0-1676533966651.png

Server script:

ElenaPomana_1-1676534024562.png

Am I missing something?

 

@Elena Pomana 

Did you get a chance to check my below response around onSubmit + Ajax?

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

Sorry, I was in a meeting and didn't get the chance to.