User criteria in service portal

muktha1
Tera Guru

I have a custom widget created in the service portal. I have activated the plugin for User criteria in the portal. Users occupying a specific field in the user table should have access to the widget. But the user criteria script is not working and everybody in the user table is able to view the widget. Can anyone please help? It is an urgent requirement.

var gr = new GlideRecord('sys_user');
gr.addActiveQuery('manager', gs.getUserID());
gr.query();
if(gr.next()){
answer =true;
}
else{
answer = false;

 

1 ACCEPTED SOLUTION

@muktha 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Suseela Peddise
Kilo Sage

Hi,

Can you confirm that you performed these steps:

1. Activate the plugin (com.glide.service-portal.user-criteria)

2. Set the user criteria for Service portal system property

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/task/activa...

3. Create a user criteria for Service Portal

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/task/create...

Script:

answer = ifScript();

function ifScript() {

var userId = gs.getUserID();

var user = new GlideRecord("sys_user");

user.addActiveQuery();

user.addQuery('manager', userId);

user.query();

return user.hasNext();

}

4. Apply user criteria for to a page,widget or widget instance

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/build/service-portal/task/widget...

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Muktha,

I think the query should be like this; if the logged in user is manager of any user

var gr = new GlideRecord('sys_user');
gr.addQuery('manager', gs.getUserID());
gr.query();
if(gr.next()){
answer =true;
}
else{
answer = false;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@muktha 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@muktha 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader