Tags:
create new tag
, view all tags

Question

I have some TWiki code that sets a variable based on the return from a SEARCH. If the search results variable (SR) is defined, we then go through another chunk of code to display the results. Otherwise (not shown here), we display a nastygram.

%CALC{ $SET(SR, %SEARCH{"META:FIELD.*name=\"Role[1-5]\".*value=\".*%FORMFIELD{"NodeName" topic="%the_topic%"}%.*\"" topic="E_*" type="regex" nonoise="on" separator=", " format="$topic" }% ) }%

%IFDEFINEDTHEN{"%CALC{$GET(SR)}%"}% 

I'd like to write the code using shorter lines, so it's easier to read on the page. However, as far as I can tell, CALC doesn't play nicely with GluePlugin.

I tried setting interim variables, but that stopped working at the last step in the chain.

   %CALC{ $SET(T0, %FORMFIELD{"NodeName" topic="%the_topic%"}%                   ) }%
   %CALC{ $SET(T1, $NOEXEC(META:FIELD.*name=\\"Role[1-5]\\".*value=\\".*           ) ) }%
   %CALC{ $SET(T2, $NOEXEC(topic="E_*" type="regex" nonoise="on" separator=", " ) ) }%
   %CALC{ $SET(T3, "$EXEC($GET(T1))$EXEC($GET(T0)).*\\"" $EXEC($GET(T2))         ) }%
   %CALC{ $SET(SR, %SEARCH{ %CALC{ $GET(T3) }% format="$topic" }%                 ) }%

%IFDEFINEDTHEN{ "%CALC{ $GET(SR) }%" }% 

I'm hoping I just missed seeing something trivial and that someone will say "Oh, do it this way".

Environment

TWiki version: unspecified
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Search

-- RichMorin - 17 Aug 2008

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

I am not sure I follow what you intend to do. I usually set CALC variables in a SEARCH format, then use the result after the SEARCH.

Incomplete example:

%CALC{$SET(sum, 0)}%
%SEARCH{ .... format="$percntCALC{$SETM(sum, + $formfield(Price))}$percnt" }%

Total: %CALC{$GET(sum)}%

-- PeterThoeny - 17 Aug 2008

We're just looking for a way to avoid having 200-character lines. CALC seemed like a possibility, but we couldn't make it work.

-- RichMorin - 17 Aug 2008

> as far as I can tell, CALC doesn't play nicely with GluePlugin.

Did you configure it to "glue" before it "calcs"? I.e., (as per the plugin's page):

$TWiki::cfg{PluginsOrder} = 'GluePlugin,IfDefinedPlugin,SpreadSheetPlugin'

Failing that, you have a CALC inside a SEARCH inside a CALC. I don't know what the order of operations is in that case, but you don't need CALC twice. You might also need to escape the SEARCH (similar to a nested search, like so:

%CALC{$SET(SR,$percntSEARCH{\"$GET(T3)\" format=\"$topic\"}$percnt)}%

-- SeanCMorgan - 18 Aug 2008

Thanks, Sean! We added GluePlugin to the PluginsOrder and helped a lot. (We also tried adding IfDefinedPlugin, but it broke some things for us, so we took it back out for the moment.)

In any case, here is the working code:

%~~ CALC{ $SET(SR,
~~~   $percntSEARCH{search="META:FIELD.*name=\"Role[1-5]\".*value=\".*
*~~     %FORMFIELD{"NodeName" topic="%the_topic%"}%.*\"" topic="E_*"
~~~     type="regex" nonoise="on" separator=", " format="$topic" }$percnt ) }%

-- RichMorin - 19 Aug 2008

You can also define some preferences variables on web level or site level to shorten the long lines.

-- PeterThoeny - 19 Aug 2008

I'm glad that helped Rich.

It looks like I can change this to "Answered", so I will: please change it back if that's premature.

(If your IfDefinedPlugin issue is a showstopper for you, that would be better dealt with in a new question, or perhaps a bug report).

-- SeanCMorgan - 19 Aug 2008

 
Change status to:
Topic revision: r10 - 2009-07-08 - SeanCMorgan
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.