"Starts With" condition on Workflow "If" activity not working as expected

bostonsnow
Kilo Guru

Hello,

I have an "If" activity set up on a workflow that I cannot get to work. On my If activity is a "starts with" condition that I'd like to use to identify Select Box variable choices that start with certain text. 

For example:

I have a Select Box variable on a catalog item that is named "Services". This Select Box contains the following choices:

  • Services - Service Category 1 - Service Name 1
  • Services - Service Category 1 - Service Name 2
  • Services - Service Category 1 - Service Name 3
  • Services - Service Category 1 - Service Name 4

Instead of adding an individual "IS" condition for each of these choices I would like to use the "starts with" condition to capture all of the services in Service Category 1. I set up the condition as follows:

Variables - My Catalog Item - Services - starts with - "Services - Service Category 1"

This condition is not working. What am I doing wrong?

Thanks,

Mike

1 ACCEPTED SOLUTION

bostonsnow
Kilo Guru

Hello all,

Apologies for the drop in communication. I was able to get this working using the Condition builder and the Value prefix of the Variable choices.

So in the Condition builder I entered:

Variables - My Catalog Item - Services - starts with - "services__service_category_1"

Thanks so much for all of the input, it's very much appreciated.

Mike

View solution in original post

9 REPLIES 9

Brian Lancaster
Tera Sage

I'm not sure you can use the condition builder if you want to use item variables.  I think you will need to check the advanced and script it.  The script is mostly setup for you.  You just need to add the if statement.

if (current.variables.yourvariablename.startsWith("Services - Service Category 1"))

if this does not work try adding toString()

if (current.variables.yourvariablename.toString().startsWith("Services - Service Category 1"))

Thanks for the reply Brian! I plugged in this script under Advanced on the If activity and modified it with my real values but I'm getting some errors on the script.

find_real_file.png

Would you be able to help me fix whatever is wrong with this script? My scripting knowledge is limited. I changed the script back to using fake values for this example...

-----------------------------------------------

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
answer = ifScript();

function ifScript() {
if (current.variables.yourvariablename.startsWith("Services - Service Category 1") {
return 'yes';
}
return 'no';
}

-----------------------------------------------

Yes, sorry I fixed my code but you need two parenthesis at the end of the if condition.  The first one closes the startsWith and the second one closes the if statement.

if (current.variables.yourvariablename.startsWith("Services - Service Category 1")) {

bostonsnow
Kilo Guru

Hi Brian, thank you for the updated script. Unfortunately, I still can't get it to work. I thought it might be because I had 2 additional Conditions in the condition builder in the same activity but I removed them, leaving only this script, and the result of the condition was a "No". Let me know if you think of anything else. Appreciate the assistance with this.