User Criteria script is not working

ramesh_r
Mega Sage

Hi All,

I have written this User Criteria on article Level this script in executing and its going to inside the IF condition but is not working as expected Please help me to resolve this issue

 

checkRegion();
function checkRegion() {

var s = gs.getUser().getRecord().getValue('u_country');
gs.addErrorMessage(s);
if(s == "IND")
{
answer = true;
}
else
{
answer = false;
}

 

User Criteria :-

find_real_file.png 

KB Article 

find_real_file.png

1 ACCEPTED SOLUTION

Brent Sutton
Mega Sage

Hi Ramesh,

Can you please try the following code in your user criteria:

answer = false; // Default to false

var userRec = new GlideRecord("sys_user");
if (userRec.get(gs.getUserID())) {
	var s = userRec.getValue('u_country');

	gs.addErrorMessage(s);
	if(s == "IND") {
		gs.addInfoMessage("My Country is: " + s);
		answer = true;
	}
}

Let me know if it worked for you.

Brent

P.S. Please mark as correct if this information helped you so the rest of the community can benefit.

View solution in original post

10 REPLIES 10

Hi Michael,

 

Sorry for late reply, i have tried the script and this script is returning correct country value but its not working as expected.

 

This is the code i used in "Can Read" Condition articel level

checkRegion();

function checkRegion() {
var answer = false; // Default to false

var userRec = new GlideRecord("sys_user");
userRec.get(gs.getUserID());
var s = userRec.getValue('u_country');

gs.addErrorMessage(s);
if(s == "IND")
{
answer = true;
}

return answer;
}

========

IND User

 

find_real_file.png

USA User

 

find_real_file.png

 

Brent Sutton
Mega Sage

Hi Ramesh,

Can you please try the following code in your user criteria:

answer = false; // Default to false

var userRec = new GlideRecord("sys_user");
if (userRec.get(gs.getUserID())) {
	var s = userRec.getValue('u_country');

	gs.addErrorMessage(s);
	if(s == "IND") {
		gs.addInfoMessage("My Country is: " + s);
		answer = true;
	}
}

Let me know if it worked for you.

Brent

P.S. Please mark as correct if this information helped you so the rest of the community can benefit.

HI Brent,

I use the above code please find the result below

If I use this user criteria in "Can Read" condition means Both USA and IND user unable to view the article 

If I use this user criteria in "Cannot Read" condition means Both USA and IND user able to view the article

and i created two user criteria and used in both "Can Read" and "Cannot Read" means Both USA and IND user unable to view the article 

Still its making confusion

 

User Criteria:-

find_real_file.png

USA User : -

find_real_file.png

 

IND User :- 

 

find_real_file.png

Hi Ramesh,

Can you please confirm that you have put the code in exactly as I specified? It should not be wrapped in the checkRegion() function that you originally had. Can you repost the code as it is when you retested.

Thanks,

Brent

HI Brent,

 

Thank you so much for your help its worked now with your code what i expected

If possible please explain what i did mistake in my previous original code with "checkRegion() function" i will help for future 

answer = false; // Default to false

var userRec = new GlideRecord("sys_user");
if (userRec.get(gs.getUserID())) {
	var s = userRec.getValue('u_country');

	gs.addErrorMessage(s);
	if(s == "IND") {
		gs.addInfoMessage("My Country is: " + s);
		answer = true;
	}
}

 

Thanks

Ramesh R