Tags:
create new tag
view all tags

SID-01998: Using CALC inside a SEARCH

Status: Answered Answered TWiki version: 4.2.1 Perl version: 5.8.8
Category: CategorySearch Server OS: Linux Last update: 10 years ago

My objective is to use %CALC to get the value of the previous cell in a table (see below) and use it to search for a topic and display its form values.

Staff Record Last, First
Sx0123 %SEARCH{ "%CALC{$T(R$ROW():C$COLUMN(-1))}%" scope="topic" nosearch="on" nototal="on" expandvariables="on" format="$formfield(LastName), $formfield(FirstName)" }%

Column 1 (Sx0123) is a topic with a Form containing LastName and FirstName fields.

What am I missing? Thanks.

-- Bob Mellinger - 2014-12-04

Discussion and Answer

The problem is that %CALC is not evaluated inside-out & left-to-right like other variables. The %CALCULATE has the proper evaluation order, but it does not support references to table cells. This is documented in SpreadSheetPlugin.

In your case you need to delay the %SEARCH so that it evaluates after %CALC. Untested:

%CALC{$NOP(%)SEARCH{ "$T(R$ROW():C$COLUMN(-1))" scope="topic" nosearch="on" nototal="on" expandvariables="on" format="$formfield(LastName), $formfield(FirstName)" }$NOP(%)}%

In your case it might be faster to use %FORMFIELD instead of %SEARCH. Untested:

%CALC{$SET(topic, $T(R$ROW():C$COLUMN(-1)))$NOP(%)FORMFIELD{ "LastName" topic="$GET(topic)" }$NOP(%), $NOP(%)FORMFIELD{ "FirstName" topic="$GET(topic)" }$NOP(%)}%

Consider hiding the formula in a FIRSTLASTNAME preferences setting so that you can simply write:

Sx01234 %FIRSTLASTNAME%

-- Peter Thoeny - 2014-12-05

Closing this question after more than 30 days of inactivity. Feel free to reopen if needed. Consider engaging one of the TWiki consultants if you need timely help. We invite you to get involved with the community, it is more likely you get community support if you support the open source project!

-- Peter Thoeny - 2015-12-03

      Change status to:
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.
SupportForm
Status Answered
Title Using CALC inside a SEARCH
SupportCategory CategorySearch
TWiki version 4.2.1
Server OS Linux
Web server Apache 2.2.22
Perl version 5.8.8
Browser & version Chrome
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2015-12-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-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.