Question

In Orchard 1.7.1.0, I have a Custom Contact form with a drop-down:

Preferred location: North Office | South Office

I need to be able to fire an email to the relevant office based on the selection from the contact form. Simples yes??

I created a decision node in the workflow, but I'm not sure on the rules syntax based on a token..? The token would be something like {Content.Fields.ContactUsForm.PreferredLocation}

The help text is "You can use ContentItem, Services, WorkContext, and T(). Call SetOutcome(string outcome) to define the outcome of the activity." But I can't seem to find much else on the syntax - I assumed it just accepts C# as I've seen this mentioned on blog posts but I can't seem to get a simple conditional statement running.

The problem I'm having? ..Nothing happens.. No outcomes are fired. If I just put something like SetOutcome("North Office"); in the script field that gets actioned.

This is similar to this post, but the author didn't follow up how he got on and he was advised to use rules, so probably not as relevant to 1.7.1 Orchard. Orchard Custom Form DropDownLists

So anyway, this is my workflow and the code is below.

Workflow

Thanks for any suggestions..

The script I'm using, because I'm using tokens I've prefixed them with #

if (  #{Content.Fields.ContactUsForm.PreferredLocation} == "North Office") { 
SetOutcome("North Office");  }
else if  (  #{Content.Fields.ContactUsForm.PreferredLocation} == "South Office") {
SetOutcome("South Office");  }
Was it helpful?

Solution

Found the solution was to add quotes around the tokens.

    if (  "#{Content.Fields.ContactUsForm.PreferredLocation}" == "North Office") { SetOutcome("North Office");  }
else if  (  "#{Content.Fields.ContactUsForm.PreferredLocation}" == "South Office") { SetOutcome("South Office");  }

Or even simpler:

SetOutcome("{Content.Fields.ContactUsForm.PreferredLocation}");

OTHER TIPS

Adding quotes around the tokens will fix the problem. Here is why... Your code will eventually be passed to the Mono.CSharp.Evaluator class and be run. But, before that happens, the tokens #{Content.Fields.ContactUsForm.PreferredLocation} are replaced with their values. The values turn out to be of type string. If you don't add the quotes, the string replace will drop the token values right into your code.

This code:

if (  "#{Content.Fields.ContactUsForm.PreferredLocation}" == "North Office") { SetOutcome("North Office");  }
else if  (  "#{Content.Fields.ContactUsForm.PreferredLocation}" == "South Office") { SetOutcome("South Office");  }

Will actually be executed as this code when evaluated:

 if (  "North Office" == "North Office") { SetOutcome("North Office");  }
else if  (  "North Office" == "South Office") { SetOutcome("South Office");  }

One nice benefit of this is you can then tack on any of the string methods you want. ex/ .ToLower(), .Contains(), etc. Here is an example of doing this to help with evaluating the user input. Somewhat frivolous in this case since the data comes from a drop down list.

if (  "#{Content.Fields.ContactUsForm.PreferredLocation}".ToLower() == "north office") { SetOutcome("North Office");  }
else if  (  "#{Content.Fields.ContactUsForm.PreferredLocation}".ToLower() == "south office") { SetOutcome("South Office");  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top