Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

switch case on workflow for lookup select box

Elakkiya A
Tera Contributor

I am trying to create a switch case condition on workflow for a variable with type as lookup select box.

But it's not getting the correct value from that lookup table.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

From the wf_activity_definition record for the Switch activity:

Keep in mind: 
*The Switch activity works when the selected variable or field is a type of choice list , so that the Switch activity uses all the choices as possible transition paths.  
*You can use service catalog variables as the selected 'Variable'.
*ServiceNow recommends only selecting choice list or reference type fields in the 'Variable' or 'Field' activity variables.

So a Lookup Select Box type variable is not supported with this activity, and as you discovered, does not detect the values.  You could try to manually add a Condition for each value - just use the syntax:

activity.result == 'value'

in the Condition field

BradBowman_0-1696786725441.png

If the Switch doesn't detect the Lookup Select Box value and follow the correct condition/path as the workflow is executing, another option is to use a Run Script activity setting the activity.result for each value

if (current.variables.var_name == 'value1') {
    activity.result = 'value1';
} else if (current.variables.var_name == 'value2') {
    activity.result = 'value2';
}...

, then add the same Conditions to this activity

 

 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

From the wf_activity_definition record for the Switch activity:

Keep in mind: 
*The Switch activity works when the selected variable or field is a type of choice list , so that the Switch activity uses all the choices as possible transition paths.  
*You can use service catalog variables as the selected 'Variable'.
*ServiceNow recommends only selecting choice list or reference type fields in the 'Variable' or 'Field' activity variables.

So a Lookup Select Box type variable is not supported with this activity, and as you discovered, does not detect the values.  You could try to manually add a Condition for each value - just use the syntax:

activity.result == 'value'

in the Condition field

BradBowman_0-1696786725441.png

If the Switch doesn't detect the Lookup Select Box value and follow the correct condition/path as the workflow is executing, another option is to use a Run Script activity setting the activity.result for each value

if (current.variables.var_name == 'value1') {
    activity.result = 'value1';
} else if (current.variables.var_name == 'value2') {
    activity.result = 'value2';
}...

, then add the same Conditions to this activity