Script with User Defined conditions and results

Hi all, i’m using RT5 (i installed it a week ago).

I need to create a script based on user defined conditions and results.
I created a ticket custom field (OBJ), multiple choice.

When i create a ticket and my custom field is = AAA, then send a notification to joe@abc.it,
if my custom field is = BBB, then send a notification to paul@abc.it.
Since my custom field is multiple choice, if my custom field is = AAA and BBB send a notification to joe@abc.it and paul@abc.it.

Is it possible to do? How?

Thanks for any help

Could you do a custom role instead of a custom field? This may make it harder to limit the options, but then it is easy to make a new notification action:

Admin->Global->Actions

Admin->Global->Scrips:

Thanks, but i can’t because whoever creates the ticket chooses the topic of the ticket and the application in the background should know who to send an email with the detail of the ticket

The user doesn’t set the custom field value?

Yes, but the custom field contains the topic not the recipient or the email of the recipient.
For example, the custom field choose by the requestor: press review & login credentials →
mail sent to paul@abc.it & john@abc.it

I found a solution: I add the emails to the AdminCCs and then send the emails to the AdminCCs. To add the AdminCC I found this script:

my $owner_id = $self->TicketObj->Owner;
my $requestor_email = $self->TicketObj->RequestorAddresses;
my $admincclist = $self->TicketObj->AdminCc;
my @actors = ('pippo@company.com', 'pluto@company.com');
my $user = RT::User->new($RT::SystemUser);

foreach my $actor (@actors) {
$user->LoadByEmail($actor);
my $user_id = $user->Id;
my $user_email = $user->EmailAddress;
if ( $user_email ne $requestor_email )
{
my($status, $msg) = $admincclist->AddMember($user->Id);
unless( $status ) {
$RT::Logger->warning( "Non è stato possibile aggiungere gli AdminCC" );
return undef;
}
}
}

what I need to do now is to fill @actor based on the custom field. I have to scroll all the selection of the custom field and if i find “AAA” then add to @actor pippo@company.com, if i find “BBB” then add to @actor pluto@company.com, if i find “CCC” the add to @actor papaerino@company.com… and so on…

there is a way to do that?

Thanks

You can get custom field values from tickets like this:

my $Values = $self->TicketObj->CustomFieldValues( "OBJ" );

while ( my $Value = $Values->Next ) {
   Do something with the Value
    ...
}

You just have to know when those values are set

Thanks a lot!!!
I tried but instead of scrolling through the values, I scroll through these objects:

RT::ObjectCustomFieldValue=HASH(0x55ef749400a8)
RT::ObjectCustomFieldValue=HASH(0x55ef74824dd8)

my $Values = $self->TicketObj->CustomFieldValues( "Ambito" );
while ( my $Value = $Values->Next ) {
      if ($Value eq 'Networking')
            {
             $actors[0] = ('pippo@company. com');
                $RT::Logger->warning( "Networking" );
             } else {
                  $RT::Logger->warning( "NetworkingNO $Value"  );
             }
      if ($Value eq 'Manutenzione')
            {
             $actors[1] = ('pippo@company. com');
                  $RT::Logger->warning( "Manutenzione" );
            } 
}

I believe you can call Content on a RT::CustomFieldValue object

Sorry but I’ve been studying request tracker and perl for a couple of weeks, and I struggle to find well-done documentation … could you tell me where to find documentation or how to call Content on RT::CustomFieldValue? I tried
my $Values = $self->TicketObj->CustomFieldValues( “Ambito” )->Content;
but doesn’t function…

I usually look at the source code for examples, I saw this:

my $values = $ticket->CustomFieldValues($id);
if ( $values->Count ) {
   $value = [ map { $_->Content } @{ $values->ItemsArrayRef } ]
}

Where that map function is turning the values object into an array (instead of using a while ( my $Value = $Values->Next ) { loop.

Your example is calling Content on RT::CustomFieldValues but believe you want the RT::CustomFieldValue (not plural) object

Thanks again

my $Values = $self->TicketObj->CustomFieldValues( "Ambito" );
while ( my $Value = $Values->Next ) {
      if ($Value->Content eq 'Networking') {

if I write my $Values = $self->TicketObj->CustomFieldValues( “Ambito” )-> Content;
is an error
but if i consider $Value->Content is correct :slight_smile:

If someone can find it useful, I write the solution I came up with thanks to @knation

my $owner_id = $self->TicketObj->Owner;
my $requestor_email = $self->TicketObj->RequestorAddresses;
my $admincclist = $self->TicketObj->AdminCc;
my @actors;
my $count=0;

my $Values = $self->TicketObj->CustomFieldValues( "Ambito" );

while ( my $Value = $Values->Next ) {
#   my $Valore = $Value->Content;
#   $RT::Logger->warning( "--- STO CERCANDO: $count - $Valore ---" );
    if ($Value->Content eq 'Networking') {
       $actors[$count] = ('xxx@nuovocircondarioimolese.it');
#      $RT::Logger->warning( "--- TROVATO: $count - $Valore ---" );
       $count ++;
    } else {
        if ($Value->Content eq 'Manutenzione') {
           $actors[$count] = ('yyy@nuovocircondarioimolese.it');
#          $RT::Logger->warning( "--- TROVATO: $count - $Valore ---" );
           $count ++;
        } 
      }
}

my $user = RT::User->new($RT::SystemUser);

foreach my $actor (@actors) {
$user->LoadByEmail($actor);
my $user_id = $user->Id;
my $user_email = $user->EmailAddress;
if ( $user_email ne $requestor_email )
{
my($status, $msg) = $admincclist->AddMember($user->Id);
unless( $status ) {
$RT::Logger->warning( "Non è stato possibile aggiungere gli AdminCC" );
return undef;
}
}
}
1;

I’ll open a new topic to turn the "if … else… " series into something like case off / switch / given …