[rt-users] Looping through transactionobj
Brent Wiese
bwiese at ElementPS.com
Wed Dec 7 14:35:43 EST 2011
You'd think as much, but it's not working like that.
I put this in condition:
if ($trans->Type eq "CustomField" && $trans->Field eq "5") {
$RT::Logger->info("Made it into 1st App condition");
return 1;
} else {
return 0;
}
Then this in Prep:
<<snip>>
$RT::Logger->info("Made it into 1st App scrip");
if ( $trans->Type eq "CustomField" && $trans->Field eq "5" ) {
$RT::Logger->info("Inside 1st App IF");
... do some stuff...
}
Ok, so that IF is EXACTLY THE SAME as the one that PASSED above. But it never makes it into the IF unless I've ONLY changed the value #5 - I have another scrip that is identical except it checks field 17 and if I've changed both 5 and 17, it logs this:
Dec 6 16:12:01 rtserver RT: Made it into 1st App condition ((eval 1581):6)
Dec 6 16:12:01 rtserver RT: Made it into 1st App scrip ((eval 1586):20)
Dec 6 16:12:01 rtserver RT: Made it into 2nd App condition ((eval 1591):6)
Dec 6 16:12:01 rtserver RT: Made it into 2nd App scrip ((eval 1596):20)
Dec 6 16:12:01 rtserver RT: Inside 2nd App IF ((eval 1596):23)
If I only change #5:
Dec 6 16:12:32 rtserver RT: Made it into 1st App condition ((eval 1411):6)
Dec 6 16:12:32 rtserver RT: Made it into 1st App scrip ((eval 1416):20)
Dec 6 16:12:32 rtserver RT: Inside 1st App IF ((eval 1416):24)
If I only change #17:
Dec 6 16:14:32 rtserver RT: Made it into 2nd App condition ((eval 1499):6)
Dec 6 16:14:32 rtserver RT: Made it into 2nd App scrip ((eval 1504):20)
Dec 6 16:14:32 rtserver RT: Inside 2nd App IF ((eval 1504):23)
I was able to get it to work if I had 1 scrip for each CF AND I put all the code in the condition box instead of the prep box. Weird to say the least. I guess I don't get the logic behind how it runs.
From: pleh.info at gmail.com [mailto:pleh.info at gmail.com] On Behalf Of Bart
Sent: Wednesday, December 07, 2011 10:42 AM
To: Brent Wiese
Cc: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Looping through transactionobj
Wouldn't it be enough to have this set of commands?
If CF1 changed, set CF2 to "hi"
If CF3 changed, set CF4 to "bye"
Without the and/or in between, a scrip is sequential so it will just run from top to bottom.
-- Bart
Op 6 december 2011 22:41 schreef Brent Wiese <bwiese at elementps.com<mailto:bwiese at elementps.com>> het volgende:
I have a scrip that checks to see if the value of certain customfield value has changed. If so, it sets the value of a different custom field.
I want to expand it to check if the value of another customfield has changed and if so, set the value of a 4th custom field.
So:
If CF1 changed, set CF2 to "hi"
and/or
If CF3 changed, set CF4 to "bye"
The scrip works fine if either CF1 or CF3 is changed, but if BOTH are changed, it's only setting CF4.
I suspect I'm only catching the highest CF ID number - the last in the set. I have some other CF's on the ticket that have ID's higher than CF1, but lower than CF3 (just the way they got added into the system) and the same thing happens if I change the value of one of them and CF1 - CF2 doesn't get changed, but CF3/CF4 works.
How do I loop through the TransactionObj to make sure I pick up all the changes? I can sort out the non-CF1/3 changes with an IF, but I can't figure out how to get my "while" statement right...
I've tried this:
my $trans = $self->TransactionObj;
while (my $customtrans = $trans->Next){ ... }
and
while (my $customtrans = $trans->Next()){ ... }
But I get:
RT: Scrip 27 Prepare failed: RT::Transaction::Next Unimplemented in RT::Action::UserDefined.
I've tried:
my $cffields = $self->TransactionObj ->CustomField;
Got:
RT: Scrip 27 Prepare failed: RT::Transaction::CustomField Unimplemented in RT::Action::UserDefined.
Tried:
my $cffields = $trans->Field;
while (my $customtrans = $ cffields ->Next()){ ... }
Got:
Scrip 27 Prepare failed: Can't call method "Next" without a package or object reference at (eval 3099) line 24
Thanks,
Brent
--------
RT Training Sessions (http://bestpractical.com/services/training.html)
* Boston - March 5 & 6, 2012
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20111207/b0eaa8e2/attachment.htm>
More information about the rt-users
mailing list