How to restrict virtual agent topic visible only for permanent employees

kamer
Kilo Expert

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:

(function execute() {
if(!vaContext.portal) {
    return false;
}

if(vaContext.portal == 'hr'){
    return true;
}
})()
1 ACCEPTED SOLUTION

Hi Mark,

Below code is working fine now.I did with GlideRecord.may be it didn't get published the topic properly.

(function execute() {
gs.info('>>> 1: ' + vaContext.portal);
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if (gr.next()){
var roletype=gr.getValue('u_person_role_type_code');
gs.info("roletype "+roletype);
}
gs.info('>>> 2: ' + roletype);
if(!vaContext.portal) {
    return false;
}
if(vaContext.portal == 'hrportal' && roletype == 'EMP'){
    return true;
}
})()
 
 
 
Thanks a lot 

View solution in original post

19 REPLIES 19

Ahhh that's a clear finding! Nice.

So how about performing a GlideRecord query?

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

LinkedIn

Or maybe even better. Because it's Virtual Agent. Can you try using:

vaInputs.user.u_role_type​

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

LinkedIn

Hi Mark,

If I use vaInputs

ReferenceError: "vaInputs" is not defined is coming.

 

 

Can you share the exact code? vaInputs. is specifically Virtual Agent. So that would be really strange.

Also just tested myself, works fine. So please share your code.

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

LinkedIn

Hi Mark,

please find the below code.

var role_type = vaInputs.user.getValue('u_role_type');