SID-01817: Comparison between two variables
| Status: |
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
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.