Displaying Virtual Agent widget depending on User ... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

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

 

The Service Portal widget for Virtual Agent is a legacy product. Agent Chat configuration is the method to apply since the New York family release.  

 

Hi there,

 

Out-of-the-box the Service Portal Virtual Agent widget is always shown on the Service Portal ones you've added it to the header/footer/a certain page. You could have the topics shown conditionally, for example depending on User properties. Though what if you would like to display the Service Portal Virtual Agent widget conditionally, depending on User properties? For example, displaying the whole widget for Users with Department HR, though not for other users (and where all users use the same Service Portal)?

Basic thought

So could we display/hide the Service Portal Virtual Agent widget based on the department of the current logged in user? For example only for the users with department "HR"?

 

If we look at the out-of-the-box Service Portal Virtual Agent widget, we could add a condition (ng-if) to the first div element in the Body HTML Template. The ng-if should then dynamically be set, based on the Server Script or the Client controller. Because user data like company/department/cost center don't change that often, we'll go for Server Script. Within the Server Script we could query the user record, to find out which department the user belongs to and if this matches our criteria. If the department matches, a property will be set which we could use in the ng-if in the Body HTML Template.

Clone and edit widget

First, we would need to clone and the out-of-the-box Service Portal Virtual Agent widget. You could do this from the Platform UI, though also through the Widget Editor.

 

Server Script

Let's first set up the Server Script. Basically, we would need to query the user record. Which department does the current logged in user have?

 

gs.getUser().getRecord().getDisplayValue('department')

 

Additionally, we would need to match the department of the user. In this example, does the user's department match "HR"?

 

if(gs.getUser().getRecord().getDisplayValue('department') == 'HR') {
	...
}

 

Additionally, this should be set as a usable property for the ng-if in the Body HTML Template.

 

var user_property_match = false;
if(gs.getUser().getRecord().getDisplayValue('department') == 'HR') {
	user_property_match = true;
}		   
data.user_property_match = user_property_match;

 

Body HTML Template

Within the first div element in the Body HTML Template now we only need to add a ng-if which checks on data.user_property_match.

 

ng-if="data.user_property_match"

 

Service Portal

Don't forget to replace/add your new cloned and edited widget to your Service Portal 😀.

Result

When logged in as a user with has HR set as department, the Service Portal Virtual Agent widget will be displayed on the Service Portal. When logged in as a user which hasn't got HR set as department, the Service Portal Virtual Agent widget will not be displayed on the Service Portal.

 

Obviously, you might want to think of a more flexible way. What if you want to check on a different department? Or multiple departments? Or not a department, though a company instead? Also, this example contains a hardcoded display value that you might want to avoid.


All possible 😀. This is just an example of how to display the Service Portal Virtual Agent widget dynamically based on user properties.

---

And that's it. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Consultant @ Quint Technology

1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

Comments
amadosierra
Kilo Guru

Hi Mark,

There seem to be another method for adding the widget to the portal by going to Service Portal > Agent Chat. This method seems to be injecting the out-of-the-box widget directly to the portals configured (it does not require to add it to the footer).

When should this method be used vs. adding it to the footer? Is there a difference?

Here's the documentation article as a reference: https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/build/service-portal/task/config...

Regards,

Amado

Mark Roethof
Tera Patron
Tera Patron

Hi there,

If it concerns solely the out-of-the-box widget for Virtual Agent, yes since new york you could use the Service Portal > Agent Chat. If you are using a customized widget, for example because you have a different bot icon, bot displayed on the left, Virtual Agent popping-up from a modal, etc., etc., then... no go, Service Portal > Agent Chat will not work for you.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

Community Alums
Not applicable

Hi @Mark Roethof 

Thanks for sharing the knowledge.  

How can the logic of showing/hiding virtual agent based on user's department, in a portal, be achieved using the "Agent Chat" record ?

I see that it can be achieved like you have explained here by cloning the widget but is there a possibility to achieve it without cloning the widget ?

Thanks

Mark Roethof
Tera Patron
Tera Patron

The Agent Chat configuration is a nice new feature with Orlando release. Though concerning visibility, it is limited to using combinations of portals and/or roles. So anything else, like the department won't be possible. So that would be a case to clone and edit the widget.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

Community Alums
Not applicable

If we enable "Service Portal User Criteria Support" plugin then we can achieve the limitation.

So if there is a need to limit the visibility based on a user criteria (like department), i believe we can still achieve it for a particular portal without cloning the widget.

Just use the related list "Can view" or "Cannot view" to manage.

Haven't tried yet but can see it on the widget.

Mark Roethof
Tera Patron
Tera Patron

Sounds interesting. I did have a look at my PDI, though on the Service Portal Agent Chat Configuration, I don't see a possibility to add the Can* / Cannot* related lists.

Can you share what you managed to do?

Community Alums
Not applicable

Spent few hours to figure that out actually. So i feel you.

I did the following steps

1) Activate the plugin - Service Portal user criteria support

2) Enable the property - glide.service_portal.user_criteria_enabled

Then you should see the "can view" and "Cannot view" on the widget.

Thanks !

Mark Roethof
Tera Patron
Tera Patron

Ah on the Service Portal widget itself? That's an interesting thought, never tried such. Will try later today!

Community Alums
Not applicable

Sure, let me know - what you figure out.

I am right now investigating - can we access the "portal" record value on the user criteria assigned to a widget?

So to identify whether the widget is on  IT portal or ESC or Facilities  - This will open lot of scenarios which standard roles/group/company cannot manage. Via the advance script.

Mark Roethof
Tera Patron
Tera Patron

Tried a little bit. Didn't get it to work with Can view / Cannot view on the Widget itself.
Though on a Widget Instance, this does work instantly!

Will have a look later again to see if on the Widget itself would be possible. So you could use this for example with the Agent Chat Configuration, because no Widget Instance is created with using that. If you would just drag/drop the widget through the Page Designer, a Widget Instance is created.

Community Alums
Not applicable

Yes exactly. As the OOTB configuration for Widget (virtual agent service portal widget) works directly with Agent chat record.

As using the agent chat record is the suggested approach in Orlando from servicenow with respect to virtual agent. At the same time there is little configuration we can do to point it to some other widget.

The legacy way of drag/drop the widget on each page is not suggested by servicenow anymore so have to figure out some way to achieve it on the Widget record itself.

Thanks for trying. I will be trying a wrapper (embedded widget) approach to achieve this.

Anne21
Kilo Contributor

Hi @BigMouth were you ever able to achieve this through trying a wrapper (embedded widget) approach?

newservicenowus
Tera Guru

@Mark Roethof did you get this working with User criteria? I've tried and it doesn't seem to in Rome.

I've been able to use it with other widgets/widget instances previously but doesn't seem to with Virtual Agent. So will try your way of cloning the widget and adding conditions to it.

Version history
Last update:
‎08-17-2024 10:05 PM
Updated by:
Contributors