Question
I'm looking for a way to capture and use the last update date of topics returned in a search. I note that I can use '$date' in a format string to return this date for topics returned in the search, but as soon as I try to use it in a calculation, it seems to use the last review date of the topic containing the search, not that of the topic returned in search.
My goal is produce a report that will compare a review period in days, as defined in an attached form, with the difference between last update and current date. This will identify documents that need to be reviewed and re-validated.
Take following search for example.
%SEARCH{ "." nototal="on" nosearch="on" order="modified" reverse="on" format="$topic - Last updated on $date by $wikiusername %CALC{"$TIME(%REVINFO{"$date"}%)"}% %CALC{$TIME()}%
$n "}%
Here I see the correct last update for topics returned in search, as expanded by $date. I then tried to convert this to serial, for comparing using $TIMEADD or $TIMEDIFF or $EVAL and found that I get same last review date for all search results - that of the search topic.
I'd like to understand the problem with this method (is seen repeatedly whether using
%REVINFO%, $date,
converting to serial or formatting as date before comparisons, evaluating difference as equation, etc). Why can't I use the
$date
search var or
%REVINFO%
to manipulate the last update date of search results? Is there another way to go about this?
Many thanks!
Environment
--
MichelleAlbertin - 29 May 2007
Answer
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.
The CALC in your SEARCH format fires off just once. You need to escape the CALC so that it executes once per search hit:
format="$topic - Last updated on $date by $wikiusername $percntCALC{$TIME($date)}$percnt"
You can put any type of formula inside
$percntCALC{...}$percnt, also nested ones and sequential ones. If needed, use
$SET() and
$GET() to have values persists over the whole search result.
--
PeterThoeny - 29 May 2007
I have not managed to get this working and I believe I've narrowed the problem down to translation of the revision date to serial, so that I can use it with a TIMEDIFF function.
Using the date var in my search format returns last revision date for the topic returned in my search, but when I use this within a calc function, it returns zero.
For example:
%SEARCH{ "." nototal="on" nosearch="on" order="modified" reverse="on" format="$topic - Last updated on $date serial: %CALC{"$TIME($date)"}% by $wikiusername $n"}%
I've also used REVINFO within my search, but this returns last udpate for the topic containing the search, not the one being returned:
%SEARCH{ "." nototal="on" nosearch="on" order="modified" reverse="on" format="$topic - Last updated on $date Time diff: %CALC{"$TIMEDIFF($percntCALC{"$TIME(%REVINFO{"$date"}%)"}$percnt, $percntCALC{"$TIME()}$percnt, minute)"}% by $wikiusername $n"}%
What I am looking for is time between current date and last update for each topic returned in a search. Is this possible?
Btw, if I take the first search I posted and escape the % as suggsted, my search breaks. In this case, it returns the text '%CALC{' after each topic and nothing more. I confess I find the escape rules for searches pretty confusing. Is it any function being called within another that requires escaping, or only a nested funciton of the same type? I.e. a CALC within a SEARCH or a CALC within a CALC?
--
MichelleAlbertin - 29 Jun 2007
You may need to escape the quote characters as well (
$quot) I've sometimes gotten CALC to work without the quotes, but it's probably an unsupported feature prone to break in the future...
--
JustinLove - 30 Jun 2007
Thanks, I will play more with escaping quote, but search aside, my first question still stands. How can I use following function within a search, to return REVINFO for a topic returned in search, as opposed to the topic containing the search statement. To illustrate:
%CALC{"$TIMEDIFF($TIME(%REVINFO{"$date"}%), $percntCALC{$TIME()}$percnt, day)"}%
Seems to correctly return difference between now and last update of this topic:
1792.34915509259
%SEARCH{ "HowToSetMultipleFormCheckboxes " nototal="on" nosearch="on" order="modified" reverse="on" format="$topic - Last updated on $date serial: %CALC{"$TIMEDIFF($TIME(%REVINFO{"$date"}%), $percntCALC{$TIME()}$percnt, day)"}% by $wikiusername $n"}%
Returns other topics in search result, but same differences between now and last update of this topic:
WebStatistics - Last updated on 2012-05-28 - 04:02 Elapsed update time: 1792.34915509259 by
TWikiAdminGroup
SID-01447 - Last updated on 2012-04-17 - 06:04 Elapsed update time: 1792.34915509259 by
PeterThoeny
SID-01001 - Last updated on 2012-04-03 - 19:54 Elapsed update time: 1792.34915509259 by
PeterThoeny
--
MichelleAlbertin - 02 Jul 2007
Problem solved. It looks to be down to the nesting of CALCs. I had been using a CALC each time I used a spreadsheet function. When I used a single CALC to enclose multiple functions, this worked.
--
MichelleAlbertin - 02 Jul 2007