- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 04-05-2022 07:23 AM
A request was received to create a Virtual agent topic that only specific users could see based on User Criteria. This is the same user criteria used in the Knowledge base and Service Catalog to restrict items there.
After building my Virtual Agent Conversation I navigated to the Properties tab of the conversation, selected 'Script' next to the Condition label and clicked the Add Script box.
In the box that pops up I added the following script (updating the <insertSysID> with the sys_id from the [user_criteria] table.
(function execute() {
var UCSysid = '<insertSysID>'; //sysid of the user criteria required
//Get all user criteria sys_ids
var userCriteria = SNC.UserCriteriaLoader.getAllUserCriteria();
//If user is added to UCSysid variable User Criteria, set to true
if (userCriteria.indexOf(UCSysid) > -1) {
return true;
}
else{
return false;
}
})()
After clicking Publish, the topic will only be displayed to the logged in users with that User criteria.
- 1,907 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
UserCriteriaLoader.getAllUserCriteria() method is a deprecated method and we advice using userMatches() instead.
☞ Please refer to this article below, which explains on this in detailed.
https://www.servicenow.com/community/now-platform-blog/a-deep-dive-to-user-criteria/ba-p/2281285
Below are additional Knowledge articles which discusses Semaphore Exhaustion caused by the getAllUserCriteria function being called in widgets:
Semaphore Exhaustion is caused due to the getAllUserCriteria function getting called in widgets