Damn, this really is kinda cool ^_^ (learn something new every day)<div><br></div><div>To recap what I did.</div><div><br></div><div># Go to the place where all the actions are located</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">cd /opt/rt4/lib/RT/Action</font></div>
<div><br></div><div># Copy EscalatePriority to TEST.pm, I needed an example ;)</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">cp EscalatePriority.pm TEST.pm</font></div><div>
<br></div><div># Edit TEST.pm to look like this (full content)</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">=head1 NAME</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  RT::Action::TEST</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">=head1 DESCRIPTION</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">Some test script, will increase the value of a CF by 5.</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">    CF = CF +  5</font></div><div><font class="Apple-style-span" face="'courier new', monospace">=cut</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">package RT::Action::TEST;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">use base 'RT::Action';</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">use strict;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">sub Describe  {</font></div><div><font class="Apple-style-span" face="'courier new', monospace">  my $self = shift;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">  return (ref $self . " will increase the value of a CF by 5..");</font></div><div><font class="Apple-style-span" face="'courier new', monospace">}</font></div>
<div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" face="'courier new', monospace">     </font></span></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">sub Prepare  {</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    my $self = shift;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">    my $new_value = $self->TicketObj-> FirstCustomFieldValue( 'Teller New' ) + 5;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    $self->TicketObj->AddCustomFieldValue(Field => 'Teller New', Value => $new_value, RecordTransaction => 0 );</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">    return 1;</font></div><div><font class="Apple-style-span" face="'courier new', monospace">}</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">sub Commit {</font></div><div><font class="Apple-style-span" face="'courier new', monospace">    # ---- I'll see if I can add some error logging here ----</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">}</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"># ---- Is this one needed? ----</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">RT::Base->_ImportOverlays();</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace">1;</font></div>
</div><div><br></div><div># Then launch rt-crontool like this as a test for all new tickets: (it should edit roughly 6000 tickets in my test environment)</div><div><br></div><div><font class="Apple-style-span" face="'courier new', monospace">/opt/rt4/bin/rt-crontool --search RT::Search::FromSQL --search-arg "status = 'new'" --action RT::Action::TEST</font></div>
<div><br></div><div>The last bit takes a while to complete but I find that understandable (it's a slow test server, it's swapping memory like crazy and CPU load is rather high, production has more memory and more CPU's / stronger CPU's so it shouldn't be much of a problem there ^_~)</div>
<div><br></div><div>One last question though, this custom action is only loaded when I explicitly call for it? (I assume yes, but want to be sure if it)</div><div><br></div><div>Other then that this is allot "cleaner" then hacking the SQL database. (and it's silent ^_^)</div>
<div><br clear="all">-- Bart<br>
<br><br><div class="gmail_quote">Op 8 december 2011 11:17 schreef Ruslan Zakirov <span dir="ltr"><<a href="mailto:ruz@bestpractical.com">ruz@bestpractical.com</a>></span> het volgende:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Thu, Dec 8, 2011 at 14:01, Bart <<a href="mailto:bart@pleh.info">bart@pleh.info</a>> wrote:<br>
> Can the rt-crontool launch an internal RT scrip (e.g. a global scrip or<br>
> something like that) as action instead of the actions that I come across at<br>
> the examples?<br>
<br>
</div>It's exactly what it does - replays custom condition, scrip and<br>
template combination on every ticket returned by a custom search.<br>
<br>
You need RT::Action::IncreaseCustomField module and there do something like:<br>
<br>
my ($status, $msg) = $ticket->AddCustomFieldValue(<br>
    Field => "CF",<br>
    Value => $ticket->FirstCustomFieldValue("CF") + 5,<br>
);<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Best regards, Ruslan.<br>
</font></span></blockquote></div><br></div>