Tags:
create new tag
view all tags

SID-01817: Comparison between two variables

Status: Answered Answered TWiki version: 5.1.4 Perl version: 5.8.8
Category: CategoryAutomation Server OS: CentOS release 5.9 Last update: 12 years ago

Forgive me if this is a newbie question. I'm having trouble in a comparison between two variables using %IF.

I'm using Workflow Plugin to implement an approval scheme. I would like to make the approved revision of a document to appear with a different background image than prior revisions or newer revisions.

At the beginning of the document I have set a variable of the revision currently seen:

  • Set MYREV = %%CALC{ "$UPPER(urlparam)" }%{"rev" default=%%CALC{ "$UPPER(revinfo)" }%{\"$rev\"}%}%

I would like to compare MYREV and WORKFLOWLASTREV_APPROVED.

%MYREV% and %WORKFLOWLASTREV_APPROVED% show the correct values, but %IF is always resulting the same thing, as if it is evaluating the name of the variables, not its values.

I have tried: "$ MYREV=$ WORKFLOWLASTREV_APPROVED" "'%MYREV%'='%WORKFLOWLASTREV_APPROVED%'"

How is the correct way to do the %IF? There are another way or plugin to implement this?

-- Marcos Yamaguti - 2013-11-07

Discussion and Answer

%CALC is not evaluated in the usual left-to-right, inside-out order like most TWiki variables. That is %CALC is evaluated too late compare to the %IF you are trying to use. Use %CALCULATE instead. You might need to upgrade the SpreadSheetPlugin in case you have an older version.

I am not familiar with the WorkflowPlugin. That plugin's variable also need to be evaluated left-to-right, inside-out.

-- Peter Thoeny - 2013-11-07

Thanks for your reply!

The construction %CALCULATE{$IF(%%CALCULATE{ "$UPPER(urlparam)" }%{"rev" default=%%CALCULATE{ "$UPPER(revinfo)" }%{\"$rev\"}%}%==71, revision 71, not revision 71)}% works!

But a similar one using %WORKFLOWLASTREV_APROVADO% is not:

%CALCULATE{$IF(%WORKFLOWLASTREV_APROVADO%==57, revision 57 is the approved one, revision 57 is not the approved one)}%

%WORKFLOWLASTREV_APROVADO% appears to be returning a boolean in this context, since it makes the if condition true for any value different of 0. There are any way to make it return its value?

-- Marcos Yamaguti - 2013-11-08

Well, I have decided to try something different to get WORKFLOWLASTREV_APPROVED

I have tried the search below. It is returning (.*?)\s.*)"

The search is correct, it is detecting the META line at the end of the file, but pattern does not seem to get it, it returns the end of the line of my own code. Does pattern works on META data?

%SEARCH{ "\sLASTVERSION_APPROVED=" type="regex" topic="%TOPIC%" nosearch="on" nototal="on" format="$pattern(.*LASTVERSION_APPROVED=(.*?)\s.*)" }%

-- Marcos Yamaguti - 2013-11-08

I am confused about the nested CALCULATE and multiple % signs, but I am glad the first part works as expected.

WORKFLOWLASTREV_APPROVED seems to be evaluated not in the usual left-to-right, inside-out order. That is, if you enclose WORKFLOWLASTREV_APPROVED in CALCULATE it is not yet evaluated. You could try to use CALC here, and try to set the {PluginsOrder} configure setting to WorkflowPlugin, SpreadSheetPlugin to enforce the plugin evaluation order of the plugins not using the standard evaluation path.

-- Peter Thoeny - 2013-11-08

Amazing! It is working now!

%CALC{$IF(%%CALCULATE{ "$UPPER(urlparam)" }%{"rev" default=%%CALCULATE{ "$UPPER(revinfo)" }%{\"$rev\"}%}% == %WORKFLOWLASTREV_APPROVED%, approved,not approved)}%

Thank you very much!

-- Marcos Yamaguti - 2013-11-11

      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 Comparison between two variables
SupportCategory CategoryAutomation
TWiki version 5.1.4
Server OS CentOS release 5.9
Web server Apache 2.2.3-82
Perl version 5.8.8
Browser & version Chrome 30.0.1599.114-1
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2013-11-11 - MarcosYamaguti
 
  • 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.