Catalog Item - Who has Access

Florian Korbmac
Tera Contributor

We need a report that shows which user has access to a catalog item. Is there a way to implement this?
We only control access via user criteria and not via the service offerings.
But I can't find a way to see which users fulfill the user criteria and others may not.

Is there maybe an alternative?

1 ACCEPTED SOLUTION

@Florian Korbmac 

You won't know that in database view because user criteria is evaluated against catalog item in run-time.

But why you want the list of users for each catalog item. The number of catalog items would be huge and sys_user will also be huge. your report will be heavy.

what you can do is this to achieve your requirement

1) create a custom table which holds Catalog item (List field) and the Users (reference field) which has access to that catalog item

2) populate this table by leveraging the User Criteria API and use fix script.

3) then report on that custom table and then you know which catalog item has which users

UserCriteria - Scoped 

Script, something like this, but please enhance

Note: your script will take long time as it will iterate each record of the table "sc_cat_item_user_criteria_mtom" and for all user records

// query sc_cat_item_user_criteria_mtom table and pick the criteria sysId and the catalog item


var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
gr.query();
while (gr.next()) {
    var userSatisfying = [];
    var itemArr = [];
    var criteriaSysId = gr.getValue('user_criteria');

    var userRec = new GlideRecord("sys_user");
    userRec.addActiveQuery();
    guserRecr.query();
    while (userRec.next()) {
        var userMatches = sn_uc.UserCriteriaLoader.userMatches(userRec.getUniqueValue(), criteriaSysId);
        if (userMatches)
            itemArr.push(gr.getValue('sc_cat_item'));
    }

    // now you get all users satisfying this catalog item, insert record into that table

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Florian Korbmac 

 

https://www.servicenow.com/community/platform-analytics-forum/best-way-to-create-reports-with-relate...

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Florian Korbmac
Tera Contributor

Hi @Dr Atul G- LNG,

 

thanks for the quick response. 

That's not quite what I wanted. It would be best if I could get a list of users who can see the item for each catalogue item.
Here I ‘only’ get the user criteria. But that would also be fine. I just don't get the data displayed nicely.
I get them displayed as follows:

Catalog Item Available forNot available for
Item 1User Criteria 1User Criteria 3
Item 1User Criteria 1User Criteria 4
Item 1User Criteria 2User Criteria 3
Item 1User Criteria 2User Criteria 4

 

But I can't build a decent report from this!
I have configured the database view as follows.

 

@Florian Korbmac 

You won't know that in database view because user criteria is evaluated against catalog item in run-time.

But why you want the list of users for each catalog item. The number of catalog items would be huge and sys_user will also be huge. your report will be heavy.

what you can do is this to achieve your requirement

1) create a custom table which holds Catalog item (List field) and the Users (reference field) which has access to that catalog item

2) populate this table by leveraging the User Criteria API and use fix script.

3) then report on that custom table and then you know which catalog item has which users

UserCriteria - Scoped 

Script, something like this, but please enhance

Note: your script will take long time as it will iterate each record of the table "sc_cat_item_user_criteria_mtom" and for all user records

// query sc_cat_item_user_criteria_mtom table and pick the criteria sysId and the catalog item


var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
gr.query();
while (gr.next()) {
    var userSatisfying = [];
    var itemArr = [];
    var criteriaSysId = gr.getValue('user_criteria');

    var userRec = new GlideRecord("sys_user");
    userRec.addActiveQuery();
    guserRecr.query();
    while (userRec.next()) {
        var userMatches = sn_uc.UserCriteriaLoader.userMatches(userRec.getUniqueValue(), criteriaSysId);
        if (userMatches)
            itemArr.push(gr.getValue('sc_cat_item'));
    }

    // now you get all users satisfying this catalog item, insert record into that table

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Florian Korbmac 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader