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

The advanced user criteria is expecting the "answer" variable to be set to true or false. You had "answer" wrapped in your function so all that was returned was true or false not answer = true or false.

You probably could have done the following to get the same result:

answer = checkRegion();

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

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

		if(s == "IND") {
			rightCountry = true;
		}
		return rightCountry;
	}
}