How to Script a User Criteria Check

nullreturned
Kilo Guru

We're using the Service Desk Call application (Geneva), and the problem is that when the Call type is "Request", the entries under the "Request item" aren't filtered based off User Criteria.   I'm fine scripting the filtering out, but there are no references for this in Service Catalog.   I can model some things around the calls Knowledge v3 makes, but that falls short.   Anyone have any information around scripting for User Criteria checks?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Damian,



The user criteria is really meant to determine whether the logged in users will see specific items and categories while browsing or searching the service catalog. If you want a head start on writing a script that does it I would take a look in the ui page com.glideapp.servicecatalog_cat_item_view.


View solution in original post

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Damian,



The user criteria is really meant to determine whether the logged in users will see specific items and categories while browsing or searching the service catalog. If you want a head start on writing a script that does it I would take a look in the ui page com.glideapp.servicecatalog_cat_item_view.


Brad,


        That was perfect!   I was able to take the UI Page and code up a dynamic reference qualifier to only show available Catalog items.   Thanks again!



var ReferenceUtilities = Class.create();


ReferenceUtilities.prototype = {


      initialize: function() {


      },



      filterRequestItems: function() {


              //Start with a blank list


              var availableItems = ' ';


   


              //Get all active Catalog items


              var catItem = new GlideRecord('sc_cat_item');


              catItem.addActiveQuery();


              catItem.query();


   


              //For each Catalog item


              while ( catItem.next() ) {


                      var item = GlideappCatalogItem.get(catItem.sys_id);


           


                      //If it's an actual item, and the current user can access it, add it to the CSV of sys_ids


                      if (item != null && item.canView()) {


                              if ( availableItems.trim().length == 0 ) {


                                      availableItems = catItem.sys_id;


                              }


                              else


                              {


                                      availableItems += ',' + catItem.sys_id;


                              }


                      }


              }


   


              //Return the advanced Ref Qualifier


              return 'sys_idIN' + availableItems;


      },



      type: 'ReferenceUtilities'



};



I was able to use this and it was very helpful.   But I want to take the concept a step further and test against a specific user, rather than the current logged in user. Is there a way to do that?   Maybe using the user id, or the sys_id of the sys_user record?


Community Alums
Not applicable

Ron,



I know i'm a little late in replying to this, but I wanted to say, when you use gs.getUser(), you're retrieving the entire user object. If you were to use .canView() on an entire user object. e.g. gs.getUserByID('user_id_here')