- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 12:38 AM
Hi Team,
I have few hr topics which i need to restrict those for only permanent employees.we have custom field created on user table as "Role type" which is a choice field of contract and permanent.when logged in user is permanent employee then only my topic should visible.
I have added script in condition of the topic to available only for hr portal.Now how to add my script to fetch the user table field and check if logged in user is permanent employee then show this topic
condition:
Solved! Go to Solution.
- Labels:
-
Virtual Agent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:03 AM
Hi Mark,
Below code is working fine now.I did with GlideRecord.may be it didn't get published the topic properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 02:41 AM
Hi Mark,
I have run code in background script then I am getting role_type correctly.
var role_type = gs.getUser().getRecord().getValue('u_role_type');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 02:50 AM
So did you also debug the script itself? With the vaContext etc.? What are the findings there?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 02:58 AM
Hi Mark,
No, in topic how to debug? As i know to check by activating log check box while we do topic preview.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 03:00 AM
For example with below code in your condition:
(function execute() {
gs.info('>>> 1: ' + vaContext.portal);
if(!vaContext.portal) {
return false;
}
var role_type = gs.getUser().getRecord().getValue('u_role_type');
gs.info('>>> 2: ' + role_type);
if(vaContext.portal == 'hr' && role_type == 'EMPLOYEE'){
return true;
}
})()
When opening your HR portal, and opening the Virtual Agent, this should be triggered and visible in the System Log.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 03:12 AM
Hi Mark,
I can see from below log getRecord cannot be used for scoped.
com.glide.script.RhinoEcmaError: Cannot find function getRecord in object com.glide.script.fencing.ScopedUser@10606b5.
Topic.bc7af795db7f0c14f612df9b5e9619e1 : Line(3) column(0)
1: (function execute() {
2: gs.info('>>> 1: ' + vaContext.portal);
==> 3: var role_type = gs.getUser().getRecord().getValue('u_role_type');
4: gs.info('>>> 2: ' + role_type);
5: if(!vaContext.portal) {
6: return false;