Service Catalog - Available For criteria on custom table?

SNGuru9
Tera Contributor

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 - 

userHasSCItemAccess();
function userHasSCItemAccess() {
    var gr = new GlideRecord('u_contract');
    gr.addQuery('contract_administrator=' + user_id);
    gr.query();
    gs.log(" has access?? " + gr.hasNext() );
    answer= gr.hasNext();
}
3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

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 👍

Thanks,
Anvesh

AshishKM
Kilo Patron
Kilo Patron

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

abirakundu23
Mega Sage

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.