create new tag
, view all tags


Hi, I'm trying to build a select list using a conditional search, based on a form value, as described below.

Check form value and return comma delimited search results if it matches 'Ora':

%CALC{"$SET(searchlist, $IF($EXACT(%FORMFIELD{DbType}%, Ora) == 1, %INCLUDE{"SelectListsToInclude" section="OracleTeam"}%, no team ) )"}%

The search in SelectListsToInclude uses a comma as separator so that these values can be used later in an edittable select list. I.e:

| select, 1, - Select Coordinator-, %CALC{$GET(searchlist)}% |

The problem is that the comma after the first name in search result is interpreted as the end of the THEN in the conditional search string. The remaining names in list then becomes the ELSE, followed by the 'no team' from the actual ELSE.

I'm looking for a clever way to distinguish the the commas in search result from the commas used in the IF statement.

I've tried to use the IF VAR, as opposed to to using the spreadsheet IF but couldn't get this returning search at all:

%CALC{"$SET(attempt4, %IF{"$EXACT(%FORMFIELD{DbType}%, Orsa) == 1" then="%SEARCH{ "Role.*value\=.*Oracle;" order="topic" regex="on" separator=" " web="%MAINWEB%" casesensitive="on" nonoise="on" format="Main.$topic,"}%" else="no team" }% )"}%

Have also tried a number of escapes on both variations. Any suggestions appreciated.


TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: Solaris 10
Web server: Apache 2
Perl version: 5.8.4
Client OS: Windows XP SP2
Web Browser: firefox / IE
Categories: Search

-- MichelleAlbertin - 26 Feb 2008


ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

This can only be done by "inverting" the sequence so that %CALC{}% is evaluated after %INCLUDE{}%. TWiki always operates "inside out", so the easiest way to do what you want is to push the %CALC{}% into the inside %INCLUDE{}%.

View either as http://twiki.org/cgi-bin/view/Support/ConditionalIncludeInSelectList or as http://twiki.org/cgi-bin/view/Support/ConditionalIncludeInSelectList?Ora=1 to get either "Themis, Phoebe" or "no team":


Oracle Team:

  • Themis, Phoebe
No Team:
  • no team

Same thing, verbatim:

%CALC{"$SET(searchlist, $IF(%URLPARAM{"Ora" default="2"}% == 1, OracleTeam, NoTeam) )"}%

View either as %SCRIPTURL{view}%/%WEB%/%TOPIC% or as %SCRIPTURL{view}%/%WEB%/%TOPIC%?Ora=1 
to get either "Themis, Phoebe" or "no team":

| %INCLUDE{"%TOPIC%" section="%CALC{$GET(searchlist)}%"}% |

*Oracle Team:*
   * %STARTSECTION{"OracleTeam"}%Themis, Phoebe%ENDSECTION{"OracleTeam"}%
*No Team:*
   * %STARTSECTION{"NoTeam"}%no team%ENDSECTION{"NoTeam"}%

If you are running TWiki 4.2, you might want to add encode="quote" to the operand list of %URLPARAM{}%, which is not supported on twiki.org today.

A final word of warning which does not apply to your use case: It took me several attempts to find out that apparently TWiki 4.1.2 behaves differently from TWiki 4.2 in case a url parameter has a value of "0" - hence the strange default of "2".

-- HaraldJoerg - 26 Feb 2008

I understand the idea behind what you are suggesting, but have run into following issues / questions:

As I understand it, %URLPARAM% returns a parameter value passed with the URL used to get to the current page. As my Ora form value is set in a TWiki form attached to the same topic, %URLPARAM% expands to nothing.

I therefore resorted to using %FORMFIELD%: (note: the TWiki form input name is DbType and is a checkbox with values Ora, Syb and Ms)

%CALC{"$SET(searchlist, $IF($EXACT(%FORMFIELD{DbType}%, Ora) == 1, OracleTeam, NoTeam) )"}%

A check of the searchlist var, returns OracleTeam, as I would expect:


Using this %CALC% within the include however, returns a baffling TWiki alert to my select list:

| select, 1, - Select Coordinator-, %INCLUDE{"SelectListsToInclude" section="%CALC{$GET(searchlist)}% "}% |
Results (partial) returned to select list:
Warning: Can't find topic /option/selectStatus:inputtype=hiddenname=etcell6x1value=/S/t/a/t/u/s/:/selectname=etcell6x2size=1optionselected=selectedNew/optionoptionAssigned/optionoptionOnHold/optionoptionResolved/optionoptionCancelled............

The selectStatus refers to the select list 'Status' in the edittable row that comes after my OracleTeam select list. So what happened to the %CALC% result in my include? Replacing the same with 'OracleTeam' displays my select list.

-- MichelleAlbertin - 27 Feb 2008

Sorry, I forgot to write: I have been using %URLPARAM{...}% instead of your %FORMFIELD{...}% only because I wanted to produce a live demo within this topic (which doesn't have your form). I could have used this topic's WebForm instead, so my fault.

Your error message looks as if TWiki gets some stuff from a edittable form in HTML, which then gets "force-filtered" towards a topic name. Consider the following snippet:

  Status: <input type="hidden" name="etcell6x1" value="/S/t/a/t/u/s/">
  <select name="etcell6x2" size="1">
    <option selected="selected">New</option>
....and so on...

Could you please post your form definition? Your example above has commas where it should have vertical bars, and a stray space after %CALC{...}%, which both would explain that the form doesn't work as expected, though I could not see how this could cause such a strange error message.

-- HaraldJoerg - 27 Feb 2008

Hi Harald, Thanks for helping me troubleshoot this. Here is the relevant portion of my form:

| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attribute* |
| DbType | checkbox | 4 | Ora, Syb, Ms, Third |  | H | 

I've eliminated all spaces within both %CALC% though not sure where the commas are that should be pipes.

I also re-created my test case at it's most basic and the alert is gone but select list is still not working. With Ora checkbox ticked in the above form, here is topic source:

%CALC{"$SET(searchlist,$IF($EXACT(%FORMFIELD{DbType}%,Ora)== 1,OracleTeam,NoTeam))"}%

%EDITTABLE{format="| label,1 | select, 1, - Select Coordinator -, %INCLUDE{"SelectListsToInclude" section="%CALC{"$GET(searchlist)"}%"}% |" changerows="off"}%
| *DB Services Coorindator:* | |

Screenshot of resulting select list:


-- MichelleAlbertin - 28 Feb 2008

Ok, getting a little closer. I've played around with every combo of escape on quotes and percents that I could think of. Closest I get is a drop down with one option of all names in a line separated by commas. So I am back to trying to get the select list to use the commas in names list to list option values. Here is INCLUDE with escaped chars:

%EDITTABLE{format="| label,1 | select, 1, - Select Coordinator -,%INCLUDE{\"SelectListsToInclude\" section=\"%CALC{"$GET(searchlist)"}%\"}%|" changerows="off"}%
| *DB Services Coorindator:* | |

-- MichelleAlbertin - 28 Feb 2008

You write ...though not sure where the commas are that should be pipes. Sorry, this was a misunderstanding on my side. I didn't read carefully enough and thought you were fighting with defining a form - but actually commas are what is needed in your case of using %EDITTABLE{...}%.

The good news is that I now can reproduce what you are writing about.

The bad news is that, after some inspection of the code and docs, I am afraid that what you are trying to do is impossible, at least not with the straightforward approach we've tried so far.

Let me first quote what ought to work:

%EDITTABLE{format="| label,1 | select, 1, - Select Coordinator -, %INCLUDE{"SelectListsToInclude" section="%CALC{$GET(searchlist)}%"}% |" changerows="off"}%
| *DB Services Coordinator:* | |
You do not want to escape any quotes and percents because you want the "inner" variables to be evaluated before they get passed to %EDITTABLE{...}%.

Here are the components which work:

%INCLUDE{"SelectListsToInclude" section="%CALC{"$GET(searchlist)"}%"}%
%EDITTABLE{format="| label,1 | select, 1, - Select Coordinator -, %INCLUDE{"SelectListsToInclude" section="OracleTeam"}% |" changerows="off"}%
| *DB Services Coordinator:* | |

So both %CALC{...}% inside %INCLUDE{...} and %INCLUDE{...} inside %EDITTABLE{...}% work. Now why does %CALC{...}% inside %INCLUDE{...} inside %EDITTABLE{...}% fail?

The reason is the sequence of TWiki rendering, in its combination between so-called "common variables" and "plugin variables". %INCLUDE{...} is a common variable. Plugin variables can be handled like common variables, but unfortunately neither %EDITTABLE{...}% nor %CALC{...}% are of that kind.

The sequence is:

  1. Expand common variables (a recursive, inside-out routine).
    • During this step, the %INCLUDE{...} will not be processed because it contains an unprocessed %CALC{...}% (inside-out!), so expansion is deferred.
  2. Expand plugin variables by calling their appropriate handler.
    • On plugin execution, %CALC{...}% is expanded, but %INCLUDE{...} stays as it is.
    • The processing of %EDITTABLE{...}%, however, can not deal with variables containing {...} parameters correctly (it's in the code, and not obvious how to fix).
    • A simple %CALC{...}% within %EDITTABLE{...}% would work, because due to the plugin execution order %CALC{...}% is expanded first.
  3. Expand common variables again, in case the plugins have spit out more variables.
    • In this final step, it doesn't really matter whether there's enough left for TWiki to expand %INCLUDE{...} because it is too late for %EDITTABLE{...}% to pick up the contents of the section.

Looong story, no solution. Sorry. But maybe it gives you some inspiration to look into different approaches, or at least save you from spending more time for something which can't be done. I'm not yet prepared to surrender, but have to do different things for some hours now, or maybe someone else has an inspiration or knows about a parameter I've missed....

-- HaraldJoerg - 29 Feb 2008

I am closing this after more than 30 days of inactivity. Please feel free to reopen the question.

-- PeterThoeny - 03 Apr 2008

Change status to:
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2008-04-03 - PeterThoeny
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.