How to restrict Virtual Agent to only a specific group/groups?

MitaliJain
Tera Contributor

Can we make virtual agent icon visible based on user group? I am currently using Out-of-the-box virtual agent chat config. I am checking condition using gs.getUser().isMemberOf(), it is not working as needed. It is making visible to all.

12 REPLIES 12

Hi Mark,

 

Please find attached screenshot for script I am trying to check condition.

As per the requirement, I want to enable virtual agent with respect to group of users. 

Ah clear what you are trying now. And also... no go, so far as I know that's not possible using the server script. For example also try yourself, by only scripting return false or something, the icon will be visible anyway. You can use roles, though scripting logic like this no go as far a I know.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Thank you Mark for your response.

Rajdeep Ganguly
Mega Guru


Yes, you can make the Virtual Agent icon visible based on user group. Here's how you can do it:

1. Navigate to the Virtual Agent Designer.
2. Open the chat setup.
3. In the "Client Script" section, you can add a script to check if the user is a member of a specific group.
4. Use the gs.getUser().isMemberOf('group_name') function to check if the user is a member of the group. Replace 'group_name' with the name of your group.
5. If the function returns true, then the user is a member of the group and you can make the Virtual Agent icon visible. If it returns false, then the user is not a member of the group and you can hide the Virtual Agent icon.

Here is a sample code:

javascript
(function() {
var user = gs.getUser();
if(user.isMemberOf('group_name')) {
// code to make the Virtual Agent icon visible
} else {
// code to hide the Virtual Agent icon
}
})();


Please replace 'group_name' with the actual name of your group.

Remember:

- The gs.getUser().isMemberOf('group_name') function checks if the current user is a member of the specified group.
- The function returns true if the user is a member of the group, and false otherwise.
- You can use this function in a client script to control the visibility of the Virtual Agent icon based on the user's group membership.
- Make sure to replace 'group_name' with the actual name of your group.


nowKB.com

Could you ask your AI thing also where this client script field is? Since that's not on the Agent Chat configuration which is the question here. 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn