- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:00 AM
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 :-
KB Article
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2018 02:08 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:10 AM
I have seen issues sometimes with nested functions to the getUser(). Try this instead:
checkRegion();
function checkRegion() {
var userRec = new GlideRecord("sys_user");
userRec.get(gs.getUserID());
var s = userRec.getValue('u_country');
gs.addErrorMessage(s);
if(s == "IND")
{
answer = true;
}
else
{
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:35 AM
Doh, the function never returns the answer! Try this:
checkRegion();
function checkRegion() {
var userRec = new GlideRecord("sys_user");
userRec.get(gs.getUserID());
var s = userRec.getValue('u_country');
gs.addErrorMessage(s);
if(s == "IND")
{
answer = true;
}
else
{
answer = false;
return answer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:37 AM
Actually also noticed the answer variable was never declared, sorry, use this one instead:
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;
}