User criteria is not working as expected

Janu sree
Tera Guru

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;
    }
}


 

13 REPLIES 13

Janu sree
Tera Guru

Hi @AnveshKumar M  and @Danish Bhairag2  - 

Yes, I can see there is an existing Business rule which is on running on sn_hr_core_profile table, this particular BR is updating the checkbox of profile to true in user table. When I deactivated this business rule and impersonating users not having user profile, they are not becoming true . But still there are cross scope errors from hr source are appearing. Can you please let me know what I can do further on this as I cannot keep the br remain deactivated for my user criteria(created on EC app)

 

Janusree_0-1698988893342.pngJanusree_1-1698988920655.png

 

Hi @Janu sree ,

 

Plz do not deactivate the BR. Reactivate it.

 

Try below code instead :

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'){
userRec.setWorkflow(false);
  answer = true;
    }
    else{
userRec.setWorkflow(false);
        answer = false;
    }
}

 

Thanks,

Danish

 

Hi @Danish Bhairag2 

Tried it, It was the same issue again. HR profile false user is becoming active

But sometimes there was an error coming up as well and also I observed there is a script include which is making profile checkbox true in user table.

Janusree_0-1699007246614.png

Janusree_2-1699007603510.png

 

Janusree_3-1699007645640.png

 

But some times when I'm receiving the error when impersonating the user then the profile checkbox is not becoming true