Page 1 of 1

Addon Release: IsNewValue

PostPosted: Sat Feb 12, 2005 4:30 pm
by Parahead
This is an addon that is a direct response to the discussion in this and this thread. The first thread includes a nice example by sstoner which demonstrates the grouping of newsitems which this addon can help you with.

Anyway, within a normal Coranto installation you have the possibility to use these tags in a style which all is quite selfexplainatory:
Code: Select all
<If: Sub: isNewDate>
<If: Sub: isNewYear>
<If: Sub: isNewMonth>
<If: Sub: isNewWeek>
<If: Sub: isNewUser>
<If: Sub: isNewCategory>
<If: Sub: isNewFile>


With this addon you can use this tag in your style:
Code: Select all
<If: Sub: isNewValue: NameOfField>

Where the NameOfField is what it says, the name of the field you which to monitor if it has changed since the last newsitem in the current profile. So basically this addon replaces the above built in tags and gives you the full power to specify an arbitrary field to use without any restrictions, thus you can sort on a field of your choice and use the isNewValue tag to group the newsitems with a common header.

Sounds complicated? Well, if you didn´t understood the reference threads or what I mumbled about above, just don´t download it. But if you did understand my line of thinking and see the potential, feel free and download it. The addon is developed on a installation running Coranto 1.30.x but it should be fully functional with any release of Coranto.

Download here!

PostPosted: Thu Feb 17, 2005 3:59 am
by Psykosys
Very spiffy, thanks! I have a project that probably needs exactly this addon.

PostPosted: Thu Mar 10, 2005 8:02 pm
by Dale Ray
This addon is not limited to testing the value of one field.

You can use perl code to create a string out of the values of multiple fields and then test that value. I use this to keep duplicates from printing in a profile that prints game schedules for softball. I put the two team names, the text separator, time, etc. into one string called $game ending up with this:

Team One at Team Two, 4 p.m.

and then use:

<If: Sub: isNewValue: game><Field: game></If>

to make sure it is not the same as the entry before.

If you want you can create a profile to just list the duplicates into a text file so you can easily find them and delete them.

I am entering the schedules for 45 high school teams (in two sports) so it easy to enter a duplicate, this makes it easy to spot them.

PostPosted: Tue Sep 27, 2005 2:53 am
by Gansos
I've been using this addon to do some great things. In the process, I discovered an interesting fact that may not be apparent at first. This is a bit technical, so if you don't know PERL, you may get confused. For people who do understand PERL, this may be helpful.

Due to PERL's lazy evaluation of AND/OR operators, the following code may not perform as expected:
Code: Select all
<PerlCode>
if( isNewValue('SomeField' || isNewValue('SomeOtherField' ) {
  ...do something...
}
</PerlCode>

If the left side is true, PERL never evaluates the right side. This can be troublesome because isNewValue('SomeOtherField' ) never runs, and thus the value is not updated. The same is true for AND (&&) tests as well, except that if the left side is false, the right side is not evaluated.

The proper way to carryout such an operation would be this:
Code: Select all
<PerlCode>
$somevalue{$ProfileName} = isNewValue('SomeField');
$someothervalue{$ProfileName} = isNewValue('SomeOtherField');
if( $somevalue{$ProfileName} || $someothervalue{$ProfileName} ) {
  ...do something...
}
</PerlCode>

Now, both isNewValue tests run regardless of the logical operator tests. This is probably the desired behavior if you're using isNewValue in a logical test, like above.