How to get the Title of logged in User in Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 08:02 AM
Working on User Criteria, need to show the catalog item to the user whose title is in some specific values.
We have create a property to hold those title values.
Now we are trying to check whether user is having the title or not. Here in script it is always returning true.Below is the script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 08:25 AM
gs.getUser().title or gs.getUser.getTitle() will not work.
To get title user:
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
var Usertitle = usr.title.toString();
You can now use Usertitle for your other operations like uppercase and indexOf
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 10:23 PM
@Rakesh11 did this work for you?
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 11:01 PM - edited 10-18-2023 11:02 PM
Hi @Rakesh11
In user criteria script you should use "user_id" & not gs.getUser()
/** Scripted User Criteria is not cached, and evaluated everytime, so performance is dependent on the script.
* Populate `answer` with true/false or evaluate to true/false
* The script is evaluated in the scope the user criteria is defined
* Don't use `current` in the script or populate the variable
* Don't use `gs.getUser()` or `gs.getUserID()`,
* instead use `user_id` which contains the user sys_id against whom the evaluation is happening.
*/
/*1. Decalre variable to store user title */
var userTitle;
/*2. Glide record on user table */
var grUser = new GlideRecord('sys_user');
grUser.addQuery('sys_id',user_id); //use user_id variable to get logged-in user sys_id
grUser.query();
if(grUser.next()){
userTitle = grUser.getValue('title'); //we will get the title of logged in user
}
/*3. Use your logic below to check the user title we got from above with system property */
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates