Catalog item User Criteria Advanced Script not working

Somujit1
Tera Contributor

Hi Experts,

 

I have a custom String type field on User table named Business (u_business). I have a requirement to make a catalog item available for users who has itil role and have the Business field value as 'Technology and Digital Group'.

 

I have created a User Criteria under the Available For related list with the below script, but the it doesn't seem to enter the GlideRecord and If-Else query. Can you please help me with the correct script?

Somujit1_0-1722407248065.png

 

function getBizValue() {
var userRec = new GlideRecord("sys_user");
userRec.addEncodedQuery("active=true^u_business=Technology and Digital Group"); userRec.addQuery("user_name", user_id); userRec.query(); gs.info('Enters 1 '+user_id); gs.info ('User names '+userRec.user_name+':'+user_id);
if (userRec.next()) {
gs.info('Enters 2 '+user_id);
answer = true;
} else {
answer = false;
gs.info('Enters 3 '+user_id);
}
}
13 REPLIES 13

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

You did add some info statements for debugging, nice. But what is it providing you? Is the function triggered at all? Is any of the info statements executed? Are there values oke? Did you verify the GlideRecord query itself?

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi @Mark Roethof 

As mentioned it doesnot seem to enter the gliderecord and If-Else query, so I believe i am doing something wrong on the script for which i need a corrected one.

I had a similar post few days back, which was commented by you to apply debugging, however it didnt help. 

Thanks

Yes see my comment on user_id being a sys_id and you are quering on user_name. So that never works.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Using the 'sys_id' instead of 'user_name' doent seem to work too 😞

Thanks.