How to return no records in Advance Reference qualifier?

Community Alums
Not applicable

In location table, there is a reference field for company, which I have return following advance Reference qualifier.

javascript:new location_AdvRefQ().fncGetAllowedCompanies(); 

In the code, else part doesn't seem to be working where I don't want to return any companies if the user is not admin.

So what can the correct code be?

var location_AdvRefQ = Class.create();
location_AdvRefQ.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fncGetAllowedCompanies: function(){

strQuery = 'customer=true';

if (gs.getUser().hasRole('admin')) {
return strQuery;
}
else
{
strQuery=' ';
return strQuery;
}
},
type: 'location_AdvRefQ'
});

 

1 ACCEPTED SOLUTION

Dubz
Mega Sage

try this:

 

var location_AdvRefQ = Class.create();
location_AdvRefQ.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fncGetAllowedCompanies: function(){

strQuery = '';

if (gs.getUser().hasRole('admin')) {
strQuery = 'customer=true';
}
return strQuery;
},
type: 'location_AdvRefQ'
});

 

EDIT: Actually not sure what returning a blank value will do, if it will return no records or all records. You could try below instead if above doesn't work:

var location_AdvRefQ = Class.create();
location_AdvRefQ.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fncGetAllowedCompanies: function(){

strQuery = 'sys_id=1234';

if (gs.getUser().hasRole('admin')) {
strQuery = 'customer=true';
}
return strQuery;
},
type: 'location_AdvRefQ'
});

 

View solution in original post

4 REPLIES 4

Dubz
Mega Sage

try this:

 

var location_AdvRefQ = Class.create();
location_AdvRefQ.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fncGetAllowedCompanies: function(){

strQuery = '';

if (gs.getUser().hasRole('admin')) {
strQuery = 'customer=true';
}
return strQuery;
},
type: 'location_AdvRefQ'
});

 

EDIT: Actually not sure what returning a blank value will do, if it will return no records or all records. You could try below instead if above doesn't work:

var location_AdvRefQ = Class.create();
location_AdvRefQ.prototype = Object.extendsObject(AbstractAjaxProcessor, {
fncGetAllowedCompanies: function(){

strQuery = 'sys_id=1234';

if (gs.getUser().hasRole('admin')) {
strQuery = 'customer=true';
}
return strQuery;
},
type: 'location_AdvRefQ'
});

 

Rahul Singh8
ServiceNow Employee
ServiceNow Employee

Hi,

 

In this case you can return a filter combination which is not true for any record.

for example if the table is incident then return 'priorityIN9', which is not true for any record.

If you are returning empty or null it will give all the records present for the table.

Thanks

Rahul

apoorva_tewari
Mega Guru

You can also use:-

strQuery= "NULL";

jonivb
Mega Contributor

Hi,

You can return the following in your else statement to make sure no results are found: 

...

} else {
 
 strQuery = 'sys_id=none';

}