SCRIP User Defined Actions

Hi,

I have been looking through the available documentation for RT3 but have not
been able to locate information on what is expected or required to write a
User Defined Action for a Scrip.

My situation is this: We have a number of custom fields created (each with a
selection of values), and would like to be able to automatically assign a
value to one or more of these custom fields when a ticket is created
(usually via email submission) in one of our queues.

For example, if a ticket was submitted by email into the “Europe” queue, we
would like a custom field called “Region” to be set to “Europe”.

Could anyone provide the User Defined ‘glue’ that would be needed to
accomplish this?

With thanks.

Jeff

Jeff Klassen wrote:

Hi,

I have been looking through the available documentation for RT3 but have
not been able to locate information on what is expected or required to
write a User Defined Action for a Scrip.

My situation is this: We have a number of custom fields created (each
with a selection of values), and would like to be able to automatically
assign a value to one or more of these custom fields when a ticket is
created (usually via email submission) in one of our queues.

For example, if a ticket was submitted by email into the “Europe” queue,
we would like a custom field called “Region” to be set to “Europe”.

Could anyone provide the User Defined ‘glue’ that would be needed to
accomplish this?

With thanks.

Jeff
condition: OnCreate
action: user defined
action prep:
return 1;
action commit:
my ($status, $msg) = $self->TicketObj->_AddCustomFieldValue(
Field => ‘Region’,
Value => ‘Europe’,
RecordTransaction => 0
);
die $msg unless ($status);
return 1;

Good luck. Ruslan.

Jeff Klassen wrote:

Hi Ruslan,

Thanks for the code here. I set this up as seemed correct, but the action
does not happen. Just to confirm, I have added a scrip using the Queue
Configuration tool as follows:

Description: Set region field
Condition: On Create
Custom Condition:
Action: User Defined
Custom action preparation code:
return 1;
Custom action cleanup code:
my ($status, $msg) = $self->TicketObj->_AddCustomFieldValue(
Field => ‘Region’,
Value => ‘UBS Europe/Middle East’,
RecordTransaction => 0
);
die $msg unless ($status);
return 1;
Template: Global template: Blank

Can you see anything wrong with this setup?
Sorry. I didn’t test that. Next one right
Custom action cleanup code:
my $cf_name = ‘Region’;
my $cf = RT::CustomField->new($RT::SystemUser);
$cf->LoadByNameAndQueue(Name => $cf_name,
Queue => $self->TicketObj->Queue);
die “No such CustomField ‘$cf_name’” unless($cf->id);
my ($status, $msg) = $self->TicketObj->_AddCustomFieldValue(
Field => $cf,
Value => ‘Value’,
RecordTransaction => 0
);
die $msg unless ($status);
return 1;

Good luck.
  my ($status, $msg) = $self->TicketObj->_AddCustomFieldValue(

One catch:

Any functions matching /^_/ are RT's private internal functions.
They are not part of the exposed interface and can change at any
time.  (They're like "private" methods in Java or C++, but because
of how perl works, you aren't physically prevented from using
them.)

Private functions may change from version to version, so using
them is inviting odd code breakage and mental anguish.

In this case, the fix is easy.  There is a
RT::Ticket::AddCustomFieldValue method.  (See Ticket_Overlay.pm)

-R

Ruslan, others,

I now have the following scrip set up for a queue in our RT installation
called ‘support_em’

Description: Set region field
Condition: On Create
Custom Condition:
Action: User Defined
Custom action preparation code:
return 1;
Custom action cleanup code:
my $cf_name = ‘Region’;
my $cf = RT::CustomField->new($RT::SystemUser);
$cf->LoadByNameAndQueue(Name => $cf_name,
Queue => $self->TicketObj->Queue);
die “No such CustomField ‘$cf_name’” unless($cf->id);
my ($status, $msg) = $self->TicketObj->RT::ticket::AddCustomFieldValue(
Field => $cf,
Value => ‘UBS Europe/Middle East’,
RecordTransaction => 0
);
die $msg unless ($status);
return 1;
Template: Global template: Blank

What I would like to happen is for an email sent in to this queue to
automatically have the custom field “Region” set to “UBS Europe/Middle
East”. Ruslan has provided the code above, but this still does not work. Can
anyone spot a problem here?

Thanks a lot everyone.

Jeff

I’ve tested it. Could you provide a cat from rt.log when you create
ticket in this queue? There is must be info about error!
Next time provide debug info at once.
I’ve tried to help you, but you don’t want setup logging and just cat
some strings from. You just say: “It’s don’t work.”

Jeff Klassen wrote:

Ruslan, others,

I now have the following scrip set up for a queue in our RT installation
called ‘support_em’

Description: Set region field
Condition: On Create
Custom Condition:
Action: User Defined
Custom action preparation code:
return 1;
Custom action cleanup code:
my $cf_name = ‘Region’;
my $cf = RT::CustomField->new($RT::SystemUser);
$cf->LoadByNameAndQueue(Name => $cf_name,
Queue => $self->TicketObj->Queue);
die “No such CustomField ‘$cf_name’” unless($cf->id);
my ($status, $msg) = $self->TicketObj->RT::ticket::AddCustomFieldValue(
Why there is RT::ticket::AddCustomFieldValue? I didn’t send you such string!
It must be:
my ($status, $msg) = $self->TicketObj->AddCustomFieldValue(
or
my ($status, $msg) = $self->TicketObj->_AddCustomFieldValue(

Hi Ruslan,

I am sorry. You have been quite helpful and clearly I should have sent more
detail already.
Here is a cat from the rt.log (debug), beginning with the [error] concerning
the scrip:

[Fri Oct 24 13:22:54 2003] [info]:
rt-3.0.0-3127-14570.1.7426869282744@ubs-translations.org sent To: Cc:
Bcc: <email_address>@ubs-translations.org
(/usr/local/rt3/lib/RT/Action/SendEmail.pm:205)
[Fri Oct 24 13:22:54 2003] [error]: Scrip 36 Commit failed: No such
CustomField ‘Region’ at (eval 1516) line 5.

Stack:
[/usr/local/perl5.6.1/lib/site_perl/5.6.1/HTML/Mason/Request.pm:281]
[(eval 1516):5]
[/usr/local/rt3/lib/RT/ScripAction_Overlay.pm:192]
[/usr/local/rt3/lib/RT/Scrip_Overlay.pm:405]
[/usr/local/rt3/lib/RT/Scrip_Overlay.pm:344]
[/usr/local/rt3/lib/RT/Transaction_Overlay.pm:168]
[/usr/local/rt3/lib/RT/Ticket_Overlay.pm:3715]
[/usr/local/rt3/lib/RT/Ticket_Overlay.pm:578]
[/usr/local/rt3/lib/RT/Interface/Web.pm:285]
[/usr/local/rt3/share/html/Ticket/Display.html:70]
[/usr/local/rt3/share/html/Ticket/Create.html:242]
[/usr/local/rt3/share/html/autohandler:145]
(/usr/local/rt3/lib/RT/Action/UserDefined.pm:59)
[Fri Oct 24 13:22:54 2003] [info]: RT::Scrip=HASH(0x91ee76c): Couldn’t
commit User Defined (/usr/local/rt3/lib/RT/Scrip_Overlay.pm:345)
[Fri Oct 24 13:22:54 2003] [info]: Ticket 3127 created in queue ‘support_em’
by jklassen (/usr/local/rt3/lib/RT/Ticket_Overlay.pm:589)

Under our Global configuration there is in fact a custom field named
“Region” with type “Select one value” (there are 6 values).

The help is very much appreciated.

Jeff