User criteria check

Glenn Vattudal
Tera Expert
Hello. I am trying to use the user Criteria API to check whether a logged in user is actually in the criteria. The post I am using is: https://www.servicenow.com/community/developer-blog/usercriterialoader-api-to-evaluate-user-criteria... But I am curious as to use it since I do not want to check on a particular sys_id of a User Criteria but rather to see if the user is actually in any of the user criterias. For example: var allCriterias = new sn_uc.UserCriteriaLoader.getAllUserCriteria(gs.getUserID()); var matchingCriterias = sn_uc.UserCriteriaLoader.getMatchingCriteria(gs.getUserID(), allCriterias); if (matchingCriterias == true){ return true; } Does anyone have any suggestions? Regards, Glenn
8 REPLIES 8

Matthew Smith
Kilo Sage

I might have misunderstood your requirement here, but if you are really just trying to understand if the logged-in user matches *any* user criteria, then the following should work:

var allCriterias = new sn_uc.UserCriteriaLoader.getAllUserCriteria(gs.getUserID()); //Returns an array of any or all user criteria's matched by the logged in user

if (allCriterias.length > 0){
	return true; 
}

Vishnu Prasad K
Giga Guru

Hi Glenn,

 

Use GgetAllUserCriteria. You will be getting a list of user criterias. If it's returning any value, it means user is part of any user criteria.

I understand your requirement is to check if the user is in at least any one of the user criteria. Then the above solution can be used

Hi,

The problem I am facing is that I am trying to disable the download of attachments via link. And I am trying to use an ACL to limit this. Because it is a security concern if say a user has access to the article, copies the attachment link, and sharing it to a person that shouldn't be accessing it. The script include that I am using is the OOTB AttachmentSecurity but it is extended so I can edit the parameters.

Using a direct link overrides this. It can be done on ACL level by stating the role the user should have. However, as most know, the amount of roles would be extremely long. Hence using user criteria on the kb_knowledge (this is the table that I want to limit access to) would be preferred.

 

/Glenn

So if you want to check if a user is in a specific User Criteria you can use this?

var userCritieriaID = 'fb1166d64fff0200086eeed18110c7ab'; //example user criteria sys_id
var allCriterias = new sn_uc.UserCriteriaLoader.getAllUserCriteria(gs.getUserID()); //All logged-in users User Criteria

if (allCriterias.indexOf(userCritieriaID) > -1){
	return true; 
}