Determine current user in a Client Script?

dstuart
Kilo Expert

I have need to confirm an operation with the current user, and need to know the current user's ID.

I am familiar with gs.getUserID(), but that appears to be a server-side function, usable only in a business rule.

I also would like to use the confirm() function, which appears a client-side function, usable only in a client script.

So, is any one aware of something similar to gs.getUserID() that will work in a client script? Or something similar to confirm() that will work in a business rule?

Thanks,
Dave

16 REPLIES 16

CapaJC
ServiceNow Employee
ServiceNow Employee

Hopefully this will be useful:
http://wiki.service-now.com/index.php?title=The_g_user_Object

I cannot think of a server analog for confirm(). Since the work is being done on the server, it doesn't offer the opportunity to prompt the user for confirmation. If at all possible, that should be done on the client. But if you describe what you're trying to do, maybe someone will have an idea.


dstuart
Kilo Expert

Situation: A user is trying to update a form. I need to verify that the form being updated does, in fact, belong to the current user. If it does, fine.

If the form does not belong to the current user, I check to see if the current user has the appropriate role(s) to allow the update, and then I want to confirm with the current user that the do want to proceed.

The confirm() function will let me do the confirmation in the client script. However, I can't get the current user's ID.

I'll take another look at the g_user object and functions.

Thanks,
Dave


dstuart
Kilo Expert

Thanks for the pointers.

The g_user.userID; call gave me what I needed.


Dave


Luiz Lucena
Mega Sage

I know this post is little old, but is the closest I get to what I'm trying to find.

We have a form that HR uses to terminate employees.

On this form, we have the field: Affected User (u_requested_by).

We need some sort of prevention from HR to terminate themselves... Yes. 🙂

Could not find a way yet to get match the current user logged in the portal to the user being selected in that field.
Also, should clear the field and show a message on top.