Since you want to specify your own action code, you make the setting for
"Conditions" to “OnCreate” and “Actions” to “User-defined”. Since you
want your actions to take place while RT is doing other actions (like
creating a ticket, notifying a user, updating other fields), I recommend
you set the “Stage” to “TransactionBatch”. This ensures that all the
actions are executed in “one swell foop” (my shot at being funny).
Now, where to put the action code. I have found that when I manipulate
data and put it into a ticket record in the “Prep Code” area, it is
always available for use by any template that is being used by any other
scrip also being triggered. Which makes sense.
Putting code into a CF, we use the following type of code:
set the CF “Work-Completed Date”
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = RT::CustomField->new($RT::SystemUser);
my $cf_name = “Work-Completed Date”;
my ( undef, undef, undef, $mon, $day, $year ) = localtime( time );
my $cf_value = sprintf( ‘%d/%02d/%02d’, $year + 1900, $mon, $day );
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n”);
This is fairly simple code, but it should give you an idea of what you
need to do. Notice that even though I have no real code for “Clean-up” I
STILL put in a “return 1;”. That’s because the “Action” code is in two
parts and you want to make sure both have some sort of return to tell RT
how to act as a result of everything. If I didn’t put the “Return 1;” in
"Clean-up", the scrip would not finish and therefore the CF would not
get any info.
Also, to reference Ticket or transaction information, keep two things in
mind; the object type and the object relationship. For example: If I
want to see what kind of transaction I’m dealing with, I write
$self->TransactionObj->Type eq “Status”. I like to shorten this type of
code by creating “my $trans = $self->TransactionObj” so I don’t have to
type all that stuff over and over. All that means that if the /current/
(self) transaction is involving a change in the ticket status
(TransactionObj = “Status”). The same type of thing works for Ticket
information. However, on transactions that are “On Create”, keep in mind
whether you are trying to reference Ticket data on a ticket that hasn’t
been created yet. If I had a User-defined condition that involved an
"OnCreate", then I most likely will /not/ be able to refer to Ticket
info, since it hasn’t been created yet. I’ll need to refer to info on
the Transaction record.
Anyway, I think I got most of this correct and I hope it helps you out.
LBNLOn 6/17/2009 8:15 AM, Johnathan Bell wrote:
I’m trying to set something up where when a user creates a ticket,
some of the custom fields are automatically filled in based on the
I’m thinking that this is an application for a scrip… but I can’t
seem any detailed info on scrips other than info about the pre-built
conditions, actions, and templates. It looks like if I can specify a
custom action for the ticket create condition, I can do what I want.
However, I can’t seem to find any examples or details on what
contextual variables (eg. Ticket, Requester/Creator, Applicable Queue,
etc.) are available for Scrip code, or how to write one.
Furthermore, I know how to retrieve custom field info, but not how to
assign it from a script… what would the method to do this be?
Internet System Administrator, Baker College
Community help: http://wiki.bestpractical.com
Commercial support: firstname.lastname@example.org
Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com