Record Producer User Criteria not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi All,
I'm not sure what's wrong with this user criteria , please help me
use case : get True or false
My humble request kindly help me on this , I tried with different ways too
String(user_id) or user_id or gs.getUserID()
script :
script Include :
why info messages not coming, if this comes I have to design my major functionality
with combinaiton of System Property and User Role Check
if (system property==true)
{
if(check user role is at least one ){
answer=true;
else
answer=false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Supriya25 ,
1. If you are trying with admin. Admin users bypass the users criterias
2. impersonate a user and test you will get the message 1 time
3. if you trying to reimpersonate the same user ->User criteria are cached for the users
run the below line of code in the background script to clear the cache and try
gs.cacheFlush()
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
HI
Thanks for your suggestions
very wired thing is , from same Group , I have selected 4 peoples
I flipped property value True to False vice versa .
Property :
1.FALSE :
impersonated with user AAA : catalog item restricted and got info message also (Success)
2.TRUE :
Impersonated with. same user AAA: Catalog item still restricted
But immediately I Impersonated with BBB user, catalog item is appearing .
I did property change again
FALSE again :
immediately I Impersonated with BBB user, catalog item is disappearing .(GOOD)
TRUE :
immediately I Impersonated with BBB user, catalog item still disappearing .
making changes in system property and If I impersonated with same person again and again result not changing as per system property .
WHY like this ? any suggestions please
User Criteria
gs.addInfoMessage("Result : "+new VisibilityCondition().userCriteria(user_id));
var vc = new VisibilityCondition();
answer = vc.userCriteria(user_id);
Script Include:
userCriteria: function(userID) {
// 1. Fail early if no userID is provided
if (!userID) {
return false;
}
// 2. Fetch system configuration property
var isLoggingEnabled = gs.getProperty('trunOn_Off') === 'true';
if (!isLoggingEnabled) {
return false;
}
// 3. Define target roles
var Roles = [
'issues_user',
'wealth_user',
'tracker_user'
];
// 4. Perform an efficient check using GlideRecord
var userRoleGR = new GlideRecord('sys_user_has_role');
userRoleGR.addQuery('user', userID);
userRoleGR.addQuery('role.name', 'IN', Roles.join(','));
userRoleGR.setLimit(1);
userRoleGR.query();
// Returns true if a record exists, false otherwise
return userRoleGR.hasNext();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Supriya25
Ensure you are not testing using Admin id.
Impersonate by requested user profile and test.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Thanks you, you are right , I was checking with admin id's . thanks for making me correct .
Thanks for your suggestions
very wired thing is , from same Group , I have selected 4 peoples
I flipped property value True to False vice versa .
Property :
1.FALSE :
impersonated with user AAA : catalog item restricted and got info message also (Success)
2.TRUE :
Impersonated with. same user AAA: Catalog item still restricted
But immediately I Impersonated with BBB user, catalog item is appearing .
I did property change again
FALSE again :
immediately I Impersonated with BBB user, catalog item is disappearing .(GOOD)
TRUE :
immediately I Impersonated with BBB user, catalog item still disappearing .
making changes in system property and If I impersonated with same person again and again result not changing as per system property .
WHY like this ? any suggestions please
User Criteria
gs.addInfoMessage("Result : "+new VisibilityCondition().userCriteria(user_id));
var vc = new VisibilityCondition();
answer = vc.userCriteria(user_id);
Script Include:
userCriteria: function(userID) {
// 1. Fail early if no userID is provided
if (!userID) {
return false;
}
// 2. Fetch system configuration property
var isLoggingEnabled = gs.getProperty('trunOn_Off') === 'true';
if (!isLoggingEnabled) {
return false;
}
// 3. Define target roles
var Roles = [
'issues_user',
'wealth_user',
'tracker_user'
];
// 4. Perform an efficient check using GlideRecord
var userRoleGR = new GlideRecord('sys_user_has_role');
userRoleGR.addQuery('user', userID);
userRoleGR.addQuery('role.name', 'IN', Roles.join(','));
userRoleGR.setLimit(1);
userRoleGR.query();
// Returns true if a record exists, false otherwise
return userRoleGR.hasNext();
},
