- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 01:18 AM - edited 11-11-2024 01:24 AM
I have a script which is extension of OAuthUtil. This runs on login and run as guest user. Based on some computations we need to set some information to session.
Another requirement demands that we try to update an entry in custom table and we store sys_id of the user trying to login in a table.
Since the script runs on login, user is not logged in, and script runs as script, we are facing an issue which is occurring only sometimes.
Here is the function which returns the sys_id of the logging user.
_getUserId: function(email) {
try {
var userRec = new GlideRecord('sys_user');
var userId = '';
userRec.addQuery('email', email.trim());
userRec.setLimit(1);
userRec.queryNoDomain();
//userRec.query();
gs.info("Cherck if we recieve any result: "+userRec.getRowCount());
if (userRec.hasNext()) {
userRec.next();
userId = userRec.sys_id + '';
} else {
gs.warn("No user found for email: " + email);
}
} catch (error) {
gs.error("Error occured while fetching user id with email:: " + email + " error:: " + error);
}
return userId;
},
I am using trim and printed the email, so the email is correct.
Replaced query with queryNoDomain too
when the script fails, we dont go to catch block thus Access should not be issue according to me. On failure we are going to else block where we print no user found for email.
Another issue could be a race condition where data (sys_user) is not available yet when the script executes. But not sure how to prove this.
The scripts fails 1 out of 10 times. If it fails, we are logging again and it works next time
Looking for any leads. Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 08:53 PM
Found the root cause of the problem, the query should have worked as few teams and customers have similar implementation where they are checking user record in the instance itself.
On another question : https://www.servicenow.com/community/itsm-forum/what-are-the-capabilities-of-guest-user/td-p/471575
answer by Gaurav does say that it should query sys_user table.
So in my case after further investigation, i found that the issue happens only for new user. So the user is not present in user table in this instance, and SSO scripts create it on login, which used to run after the script i wrote.
So I moved to the logic to a script that runs after user is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 08:53 PM
Found the root cause of the problem, the query should have worked as few teams and customers have similar implementation where they are checking user record in the instance itself.
On another question : https://www.servicenow.com/community/itsm-forum/what-are-the-capabilities-of-guest-user/td-p/471575
answer by Gaurav does say that it should query sys_user table.
So in my case after further investigation, i found that the issue happens only for new user. So the user is not present in user table in this instance, and SSO scripts create it on login, which used to run after the script i wrote.
So I moved to the logic to a script that runs after user is created.