User Criteria for logged in user not working

RudhraKAM
Tera Guru

I have a user Criteria where logged in uses / users who are active can view , but seems like its not working as expected 

can some one help me whats wrong in the code 

 

scriptAut();

function scriptAut() {

var retVal;

if (gs.getUser() =="") {            // i tried this as well   if (gs.getUser() ==active) {   
 
retVal = false;

} else {

retVal = true;

}

return retVal;

}

1 ACCEPTED SOLUTION

Yes ,,  gs.getuser is not supported in user criteria ,, there is a problem ticket opened 

 

 

This is the solution given by Hi team

 

Solution Proposed: ============ IS THIS A BUG? ============

So we are dealing with a bug on our platform which is intermittent and occurs very rarely. This is recorded in PRB1319258 with the following description: Using GlideSystem objects such as gs.getUser(), gs.getUserID(), gs.getSession() in User Criteria does not work as expected consistently. This problem has been declared as "Working As Expected" with the reason that the issue happens very rarely.

============ ANY WORKAROUND? ============ However, we have a workaround in place which will involve moving your implementation to using script include (which is aware of application scope changes). This will ensure that the value returned correctly every time without failing intermittently. Please throughly review this knowledge article regarding this (has examples): https://hi.service-now.com/kb_view.do?sysparm_article=KB0719846

View solution in original post

25 REPLIES 25

Mike Patel
Tera Sage

change it to something like

condition = answer();
 
function answer(){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.addActiveQuery();
gr.query();
condition = gr.hasNext(); 
	return condition;
}

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Kam,

 

Replace if (gs.getUser() =="")  with if(gs.getUserID() == '')and try. Also Can you provide some additional details on what you are trying to accomplish?

 

Thanks,

Pradeep Sharma

ours is  a public domain , we want to show the KB articles to public and some Kbs are restricted to internal users only , in order to accomplish that we are using user criteria (can read) for some KB articles this is where my above question came in to picture , (i can use snc_internal role to fulfill this but we need script for other purpose ) . even though our code is simple its kind of not working 

 

I tried ur code too ,, its not working 

 

scriptAut();

function scriptAut() {

var retVal;

// if (gs.getUser().getRecord().getDisplayValue('department') == 'Product Management') {
//if (gs.getUser() != "") {
if(gs.getUserID() != '') {
retVal = false;

} else {

retVal = true;

}

return retVal;

}

 

Abhinay Erra
Giga Sage

My first question is, if the user is inactive can they even log in ServiceNow???!!!