IF statement always returning NO

Savitha4
Tera Contributor

I am using an IF activity in the workflow editor to check the variable's value if it is Yes or No. The script is returning No always. I have attached the script for reference.

answer = ifScript();
function ifScript() {
var getVariable = current.variables.contact_center_supervisor_access.getDisplayValue().toString();
gs.log("value is" + getVariable);
if (getVariable  == "Yes")
{
gs.log("test");
       return 'Yes';
}
else
       return 'No'; 
}

The script is printing correct values in the logs, ie the value of the variable is correct and when the IF condition is evaluated to be true the control is entering the loop but the final answer returned is NO. 

Thanks in advance.
1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Savitha,

Try below

answer = ifScript();
function ifScript() {
var getVariable = current.variables.contact_center_supervisor_access.getDisplayValue().toString();
gs.log("value is" + getVariable);
if (getVariable  == "Yes")
{
gs.log("test");
       return 'yes';
}
else{
       return 'no'; 
}
}

View solution in original post

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

Hi Savitha,

Try below

answer = ifScript();
function ifScript() {
var getVariable = current.variables.contact_center_supervisor_access.getDisplayValue().toString();
gs.log("value is" + getVariable);
if (getVariable  == "Yes")
{
gs.log("test");
       return 'yes';
}
else{
       return 'no'; 
}
}

Thanks Jaspal. It worked.

Kavita_Bhojane
Tera Guru

Hi @Savitha4 ,

 

You need to include else in parenthesis as below: 

 

answer = ifScript();
function ifScript() {
var getVariable = current.variables.contact_center_supervisor_access.getDisplayValue().toString();
gs.log("value is" + getVariable);
if (getVariable  == "Yes")
{
       gs.log("test");
       return 'Yes';
}
else{
       return 'No';
}
 
Please mark my answer correct and hit the thumb below, if it finds you helpful.
 
Thanks,
Kavita Bhojane
 

Ankur Bawiskar
Tera Patron
Tera Patron

@Savitha4 

you need not use toString() after getDisplayValue()

you need to return lowercase yes and no and not Yes and No

If my response helped please mark it correct and close the thread so that it benefits future readers.

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