Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to set specific list views for specific Groups

Shawn Horley
Kilo Guru

Greetings folks.

So, I've created specific Groups for the people about to access our new Asset Management application. I've created one of the two Views that I'm going to need. Now I'm trying to figure out how to restrict those group members to seeing the view I've created for them.

CHeers

A.

1 ACCEPTED SOLUTION

Yes. Do this

 

 

(function overrideView(view, is_list) {

if(gs.getUser().isMemberOf('<Your group name 1>') || gs.getUser().isMemberOf('<Your group name 2>')) {
answer = "Admin";
} else if(gs.getUser().isMemberOf('<Your group name 3>'){
answer = "Technicians";
} else {
answer = "default";
}
// set the new view to answer

})(view, is_list);

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

11 REPLIES 11

Question for you Sanjiv.

 

I have three groups using two different views,

Is it possible for me to add an Or statement to the view rule like this?

 

 

Or is that even a thing?

 

Question for you Sanjiv

I have three groups using two different views,

Is it possible for me to add an Or statement to the view rule like this:

 

find_real_file.png

No. Do like this

 

(function overrideView(view, is_list) {

if(gs.getUser().isMemberOf('<Your group name 1>') || gs.getUser().isMemberOf('<Your group name 2>')) {
answer = "Admin";
} else {
answer = "Technicians";
}
// set the new view to answer

})(view, is_list);

Please mark this response as correct or helpful if it assisted you with your question.

Ok so the paired Pipe acts like an or statement?

Cool. So I guess the only thing else for me to figure out is the Technician view. 

 

I realise that what I had filled into your script essentially sets the default view to the Technicians view that I had created. So the else statement should be:

else {

answer = "Default";

}

 

And then figure out how to set the technicians group view... is it possible to have a third IF term? or could I construct another If/Else after the first one?

Yes. Do this

 

 

(function overrideView(view, is_list) {

if(gs.getUser().isMemberOf('<Your group name 1>') || gs.getUser().isMemberOf('<Your group name 2>')) {
answer = "Admin";
} else if(gs.getUser().isMemberOf('<Your group name 3>'){
answer = "Technicians";
} else {
answer = "default";
}
// set the new view to answer

})(view, is_list);

Please mark this response as correct or helpful if it assisted you with your question.