user criteria of hardware catalog item

Deepika54
Tera Contributor

Hello experts,

 

I have a hardware catalog item in pc_hardware_catalog_item table.  I want that the catalog item should only be available to VIP users. For that i have created a 'Available For' user criteria containing a script but it is not working as expected . Am i doing something wrong. Kindly help

Deepika54_0-1781799877074.png

 

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Deepika54 

 

Try this script:

answer = checkVIPStatus(user_id);
function checkVIPStatus(userID) {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {
if (userGr.getValue('vip') == '1' || userGr.getValue('vip') == true) {
return true;
}
}
return false;
}

 

Note: update as necessary

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

3 REPLIES 3

IndyWanKenobi
Tera Contributor

Hello!

The if statement is where you are having issues.  I believe you are trying to use the IF statement to verify if the user_id exists. However, the if statement to achieve that would have to be:

(function() {

    var gr = new GlideRecord("sys_user");
    if (user_id) {
        gr.get(user_id);
    }

    answer = gr.vip;
})();

 

This verifies a user_id exists, before applying the getRecord call. However, because this is a user criteria, the user_id will never not exist as all user records have a sys_id and that is what user_id is referencing. So I would recommend the following:

(function() {

	var gr = new GlideRecord("sys_user");
	gr.get(user_id);

	answer = gr.vip;
})();

 

Hope this Helps!

 

Please Accept the Solution if I assisted you with your question & Mark this response as Helpful.

Thanks!

joshuajacks
Tera Guru

Using gr.vip will return an object and not the field value. You may want to use gr.getDisplayValue('vip') instead.

Tanushree Maiti
Tera Patron

Hi @Deepika54 

 

Try this script:

answer = checkVIPStatus(user_id);
function checkVIPStatus(userID) {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {
if (userGr.getValue('vip') == '1' || userGr.getValue('vip') == true) {
return true;
}
}
return false;
}

 

Note: update as necessary

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti