Service Catalog - Available For criteria on custom table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 04:05 PM
Hello!
I have created a User Criteria with advanced script. The script filters records from a custom table and returns true or false value. I wanted to check if the user criteria works on custom tables to display or hide the catalog item for a user based on script output? OR does the script only work on filtering User table records? Appreciate any suggestions. Thanks!
Here is my script -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 07:09 PM
Hi @SNGuru9
It will work on any table as long as it returns the answer variable. Modify your script like the one below.
function userHasSCItemAccess() {
var gr = new GlideRecord('u_contract');
gr.addQuery('contract_administrator=' + user_id);
gr.query();
gs.log(" has access?? " + gr.hasNext() );
return gr.hasNext();
}
answer = userHasSCItemAccess();
answer;
If the above didn't work try this one.
function userHasSCItemAccess() {
var gr = new GlideRecord('u_contract');
gr.addQuery('contract_administrator=' + user_id);
gr.query();
if(gr._next()){
return true;
} else {
return false;
}
}
answer = userHasSCItemAccess();
answer;
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 07:09 PM
Hi @SNGuru9,
You can impersonate any user who is part of u_contract table as contract_administrator.
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 08:22 PM - edited 12-01-2023 08:25 PM
Hi @SNGuru9,
Please try below steps.
answer = userHasSCItemAccess();
function userHasSCItemAccess() {
var gr = new GlideRecord('u_contract');
gr.addQuery('contract_administrator=' + user_id); // if user is contract administrator
gr.query();
if(gr.next()){
return true;
} else {
return false;
}
}
Also impersonate any user from "contract_table" that mentioned by @AshishKM.
Please mark helpful & correct answer if it's really worth for you.