- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 12:19 PM
Hello -
I am trying to setup some User Criteria on Knowledge Pages that basically will let a user who's company is active and marked as a customers along with their user is active. I have tried the below, but when applied it blocked all users with this setting. Can anyone help me fix the below code?
if (gs.getUser().getCompanyRecord().u_active_status == 'Active'
&& gs.getUser().getCompanyRecord().customer == true
&& gs.getUser().active == true)
answer = true;
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 12:30 PM
Hi Kreding,
This issue is usually faced when running the script outside a function without creating an avenue for evaluating to false:
In your case, please try the below script:
checkCondition();
function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.company.u_active_status == 'Active' && user.company.customer == true && user.active == true)
{
return true;
}
else{
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 12:26 PM
Hi,
I think it should be as below.
if (gs.getUser().getCompanyRecord().getValue('u_active_status') == 'Active'
&& gs.getUser().getCompanyRecord().getValue('customer') == true
&& gs.getUser().getRecord().getValue('active')== true)
answer = true;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 02:12 PM
For some reason it didn't work with Get Value. I appreciate the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 12:30 PM
Hi Kreding,
This issue is usually faced when running the script outside a function without creating an avenue for evaluating to false:
In your case, please try the below script:
checkCondition();
function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.company.u_active_status == 'Active' && user.company.customer == true && user.active == true)
{
return true;
}
else{
return false;
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 09:20 PM
Do not use the session API gs.getUserID in User Criteria script instead use the pre-defined variable user_id.
var userGR = new GlideRecord('sys_user');
userGR.get(user_id);
if(userGR.company.u_active_status == 'Active'
&& userGR.company.customer == true
&& userGR.active = true)
answer = true;
else
answer = false;
Mark as Correct Answer & Helpful if this solves your issue or Helpful if this is useful to you.
Regards,
Rajesh