User Criteria not working for Catalog item

mohanambalnanja
Tera Contributor

Hi All,

 

I have created a catalog item and would like to make it available which matches the below criteria.

 

If logged in user is Business Service owner, then the catalog item should be available for them.

I am trying with the below script. But it is not working.

 

var userId = gs.getUserID();

var businessServiceOwner = new GlideRecord('cmdb_ci_service');

businessServiceOwner.addQuery('owned_by',userId);
businessServiceOwner.query;

answer = businessServiceOwner.hasNext();
 
Please help me to fix this.
4 REPLIES 4

Unique45
Mega Sage

Hello @mohanambalnanja ,

you have missed the parenthesis after businessServiceOwner.query.

Add parenthesis.Rest of the code is correct.

 

 

 

var userId = gs.getUserID();
var businessServiceOwner = new GlideRecord('cmdb_ci_service');
businessServiceOwner.addQuery('owned_by',userId);
businessServiceOwner.query;
answer = businessServiceOwner.hasNext();

 

 

 

 

Please mark correct/helpful if this helps you!

mohanambalnanja
Tera Contributor

Thanks for your response. Tried after adding the parenthesis. But still, it didn't give the expected result.

 

var userId = gs.getUserID();
gs.log("LogInUser:"+userId);
var businessServiceOwner = new GlideRecord('cmdb_ci_service');

businessServiceOwner.addQuery('owned_by',userId);
businessServiceOwner.query();

answer = businessServiceOwner.hasNext();
gs.log("answer:"+businessServiceOwner.owned_by);

Akshay03
Kilo Sage
function cmdb_ser(){
var businessServiceOwner = new GlideRecord('cmdb_ci_service');
businessServiceOwner.addQuery('owned_by', user_id);
businessServiceOwner.query();

return businessServiceOwner.next();
}

Can you check with this?

SN_Learn
Kilo Patron
Kilo Patron

Hi @mohanambalnanja ,

 

Don't use `gs.getUserID()` instead use `user_id` which contains the user 'sys_id' against whom the evaluation is happening.
var businessServiceOwner = new GlideRecord('cmdb_ci_service');
businessServiceOwner.addQuery('owned_by', user_id);
businessServiceOwner.query();
if (businessServiceOwner.next()) {
    answer = true;
}
else{
	answer = false;
}

 

Please Mark My Response as Correct/Helpful based on Impact

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.