We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Check if "Requested for" account CONTAINS specific value in User criteria script

Sue143
Tera Expert
Hi all,
 
I am limiting the visibility of catalog items with an user criteria by role, but at the same time I want to check the "requested for" to see if its name CONTAINS "-ADM", if so, allow the catalog item to be requested.
 
This is my script, but it isn't working (user is not allowed to be request the catalog item where the user criteria applies):
 
answer = ifScript();
function ifScript() {
    var userObject = current.getValue("requested_for");
    if (userObject.indexOf("-ADM") > -1) {
        return 'yes';
    } else
        return 'no';
}
 
any help will be appreciated!
2 REPLIES 2

Ravi Peddineni
Kilo Sage

@Sue143 

 

requested_for is a reference and would give you a sys_ID and if you try getValue(). Could you try getDisplayValue() method instead?

AshishKM
Kilo Patron

Hi @Sue143

 

Please try the updated code.

answer = ifScript();
function ifScript() {
    var userObject = current.getValue("requested_for").getDisplayValue();
    if (userObject.indexOf("-ADM") > -1) {
        return true;
    } else
        return false;
}

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution