How can I fetch catalog item's sys_id or name in User Criteria script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 03:48 AM
Hey Folks!
I want to apply a scripted User Criteria to some of the catalog items. To determine the visibility, I need the name of the catalog item(or sys_id) of the catalog item.
I have already tried using RP.getParameterValue("sysparm_id") mentioned in this link https://community.servicenow.com/community?id=community_question&sys_id=1546cba1db1cdbc01dcaf3231f9619fe. However, it gives an error saying RP is not defined. Could you please suggest an alternative to this?
Thanks,
Akshat
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 04:21 AM
Hi Akshat,
Catalog items visibility is dependant on User Criteria & to whom it should be displayed is something that you should configure so I am not sure why there would be a need of getting the User criteria on basis of catalog item.
For instance, User with Dept 'abc' should see only 'xyz' catalog item for that you apply the user criteria for item 'xyz' & you script your criteria stating something like below.
answer=catItemRestriction();
function catItemRestriction(){
var deptInfo=gs.getUser().getRecord().getValue('department'); //Gets department from User table
var deptis="abc"; //sys_id if reference field
if(deptInfo==deptis)
{
return true;
}
else
{
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 04:29 AM
Hi Jaspal,
Thank you for your response.
The condition which determines whether the catalog item should be displayed to the logged-in user depends on the catalog item in concern. I need to query the name of the catalog item on a custom table and then determine whether the logged-in user should have access to the catalog item.
How can I determine in the User Criteria Script, for which catalog item the script is currently executing for?
Thanks,
Akshat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 05:49 AM
Hi,
What does the custom table store? which all fields it has?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 06:07 AM
Hi,
The custom table has location and company references and also discount available for user's belonging to that company and location for that catalog item. I shall check whether the logged-in user's company and location match with it.
Based on the company and location, discount is applied on the catalog item. So there could be numerous records for one catalog item in the custom table. Hence, I cannot use company and location based user criteria as these values are likely to be updated in the custom table. Also, new values will be entered in the custom table quite frequently, which means I will have to dynamically update the User Criteria every time.
I hope I was able to explain the scenario
Thanks,
Akshat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2020 07:51 AM
Hi Akshat,
Unless and until you get the catalog item sys_id it would be difficult to achieve this
I doubt this can be done; As a workaround what I would mention is allow users to open the catalog item; use onload catalog client script and determine if user should have access or not
If not then make all variables as read-only and show message to user
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader