User criteria is not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 08:58 PM
Hi Community,
I've written below User Criteria for checking if the User is having 'HR Profile' and if satisfies then showing the Quick links in EC Portal. but even if the User is not having 'HR Profile' as true in sys_user table then the script is making the HR Profile as true in user table and HR Profile table. which shouldn't be the case. Any assistance where the script is going wrong? (when checked in logs for the user with HR Profile as false, is entering into 2nd if and coming Value as 1)
var userId = gs.getUserID();
var userRec = new GlideRecord('sys_user');
userRec.addQuery('sys_id',userId);
userRec.query();
if(userRec.next()){
var profile = userRec.getValue('u_has_hr_profile');
if(profile == true){
  answer = true;
}
else{
answer = false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 09:02 PM - edited ‎11-02-2023 09:02 PM
Hi @Janu sree ,
Can u try below code:
var userId = gs.getUserID();
var userRec = new GlideRecord('sys_user');
userRec.addQuery('sys_id',userId);
userRec.query();
if(userRec.next()){
var profile = userRec.getValue('u_has_hr_profile');
if(profile == 'true'){
  answer = true;
}
else{
answer = false;
}
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 09:20 PM
Hi @Danish Bhairag2 , Tried it.
Though the user is having HR profile or not, script is going to the else condition with a profile value as '1' and not showing quick links to any of them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 09:23 PM
Hi @Janu sree ,
Wht is the type of HR profile field can u send a screenshot. Is it a checkbox?
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2023 09:33 PM