- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 08:48 PM
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.
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.
Solved! Go to Solution.
- Labels:
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 09:08 PM
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';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 09:08 PM
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';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2023 11:12 AM
Thanks Jaspal. It worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 09:15 PM
Hi @Savitha4 ,
You need to include else in parenthesis as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2023 10:19 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader