isNewValue Sub - test for change in any field

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

isNewValue Sub - test for change in any field

Postby Dale Ray » Mon Feb 07, 2005 7:37 pm

The concept of testing for a new value in any field was discussed in this thread. Here is a way to accomplish it.

You can test for a new value in any field by adding this perl subroutine to the cruser.pl file:

Code: Select all
sub isNewValue {
        ($thisValue) = @_;
   if ($thisValue ne $currentValue) { # First value
   $currentValue = $thisValue;
        return 1;
       
   }
   else { # Next same value
   return 0;
   }   
}


Here is an example style using this:

Code: Select all
<PerlCode>
$NewFlag = isNewValue($Subject);
</PerlCode>
<If: Field: NewFlag>
<Field: Subject> - NEW
<If: Else>
<Field: Subject> - Duplicate
</If>
Sub returns: <Field: NewFlag>


This example tests the subject field. Substitute the field you want to test.

I had set this up for something I was working on and then didn't need it. It has only been briefly tested. Feel free improve on this. Please post your changes.

Note: You can add your own perl subs to the fiel cruser.pl, just look for:

# ** INSERT CUSTOM SUBROUTINES HERE **
# Below is the place to put in any custom subroutines you have. (If you don't
# know what this means, just ignore this section.)


and add your routines below that.

You must remember to not overwrite the cruser.pl file when upgrading Coranto.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Re: isNewValue Sub - test for change in any field

Postby Parahead » Tue Feb 08, 2005 6:28 pm

Dale Ray wrote:You can test for a new value in any field by adding this perl subroutine to the cruser.pl file:

Code: Select all
sub isNewValue {
        ($thisValue) = @_;
   if ($thisValue ne $currentValue) { # First value
   $currentValue = $thisValue;
        return 1;
       
   }
   else { # Next same value
   return 0;
   }   
}
Dale Ray, just a word of cousion, it is not possible to use this routine from within several profiles at the same time, since then the $currentValue will not be correct then. Also, a minor problem though, it is not possible to use it multiple times in the same style based on the same logic... I have previously posted another suggestion for this type of isNewValue sub in this thread.

If there is a demand for creating a more generic version of this routine as suggested in the thread you linked to above I could fairly easy put together an addon as suggested in that thread? Hmmm...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby Dale Ray » Tue Feb 08, 2005 7:10 pm

Parahead,

I actually don't use this routine right now, I was working on a project that I came up with it for and the project died.

I posted it because of the thread I mention in the first post in case anyone else needed it.

I think that the best solution is to put one isNew sub in the core that can work for any field.
Dale Ray
User avatar
Dale Ray
 
Posts: 1001
Joined: Sun Jan 19, 2003 6:02 pm
Location: NW Indiana

Postby Parahead » Tue Feb 08, 2005 8:14 pm

Dale Ray wrote:Parahead,

I actually don't use this routine right now, I was working on a project that I came up with it for and the project died.

I posted it because of the thread I mention in the first post in case anyone else needed it.
Yeah, I did get that part, maybe I shouldn´t have directed myself specifically towards you in the answer... :-) Just wanted to save anyone the troubleshooting if using the sub with multiple profiles and/or multiple times in the same style. If using within one profile for a single field it works just great! :)

Dale Ray wrote:I think that the best solution is to put one isNew sub in the core that can work for any field.
I agree, in the meantime I can see if I can whip up an addon for it...
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden


Return to Customization

Who is online

Users browsing this forum: No registered users and 0 guests

cron