- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:26 AM
Hello,
Facing a deadline for a go-live and am having issues with the User Criteria for a Service Catalog category.
Basically I just want to show the SC Category to users who have a relationship on their user record to any CI with a name starting in "XYZ". The line of script I currently have to do this is not working (highlighted below). Can anybody help?
------------------------------------------------------------------
answer = checkAccess();
function checkAccess(){
var ci_user = new GlideRecord('sys_user');
ci_user.get(gs.getUserID());
var ci_rel_person = new GlideRecord('cmdb_rel_person');
ci_rel_person.addEncodedQuery(ci.namestartsWithXYZ);
ci_rel_person.addQuery('user', ci_user.sys_id);
ci_rel_person.query();
if (ci_rel_person.next()){
return true;
} else {
return false;
}
return true;
}
------------------------------------------------------------------
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:36 AM
Here you go.
answer = checkAccess();
function checkAccess(){
var ci_user = new GlideRecord('sys_user');
ci_user.get(gs.getUserID());
var ci_rel_person = new GlideRecord('cmdb_rel_person');
ci_rel_person.addQuery('ci.name', 'STARTSWITH', 'XYZ');
ci_rel_person.addQuery('user', ci_user.sys_id);
ci_rel_person.query();
if (ci_rel_person.next()){
return true;
} else {
return false;
}
}
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:30 AM
Try this:
answer = checkAccess();
function checkAccess(){
var str = "ci.namestartsWithXYZ";
var ci_user = new GlideRecord('sys_user');
ci_user.get(gs.getUserID());
var ci_rel_person = new GlideRecord('cmdb_rel_person');
ci_rel_person.addEncodedQuery(str);
ci_rel_person.addQuery('user', ci_user.sys_id);
ci_rel_person.query();
if (ci_rel_person.next()){
return true;
} else {
return false;
}
return true;
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:32 AM
ci.namestartsWithXYZ is string , please replace the same with "ci.namestartsWithXYZ".
answer = checkAccess();
function checkAccess(){
var ci_user = new GlideRecord('sys_user');
ci_user.get(gs.getUserID());
var ci_rel_person = new GlideRecord('cmdb_rel_person');
ci_rel_person.addEncodedQuery('ci.namestartsWithXYZ');
ci_rel_person.addQuery('user', ci_user.sys_id);
ci_rel_person.query();
if (ci_rel_person.next()){
return true;
} else {
return false;
}
return true;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:36 AM
Here you go.
answer = checkAccess();
function checkAccess(){
var ci_user = new GlideRecord('sys_user');
ci_user.get(gs.getUserID());
var ci_rel_person = new GlideRecord('cmdb_rel_person');
ci_rel_person.addQuery('ci.name', 'STARTSWITH', 'XYZ');
ci_rel_person.addQuery('user', ci_user.sys_id);
ci_rel_person.query();
if (ci_rel_person.next()){
return true;
} else {
return false;
}
}
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2019 11:39 AM
That worked, thanks so much Pradeep!
Prateek and Ayush, thank you both for your quick responses!