Make a group be admincc when a ticket is created


#1

Hello everyone

I’m trying to write a scrip to do the following:
when a ticket is created and the requester is in “Agents” group, make “NOC” group be admincc of that ticket.
here is my code:

custom Condition:

my $requestorsGroupObj = RT::Group->new($RT::SystemUser);
$requestorsGroupObj->LoadTicketRoleGroup(Type => ‘Requestor’, Ticket => $self->TicketObj->id);
if( $self->TransactionObj->Type eq “Create” && $requestorsGroupObj->LoadTicketRoleGroup(Type => ‘Requestor’, Ticket => $self->TicketObj->id) == “Agents”)
{
return 1;
}
return 0;

Custom action commit code:

my $admincclist = $self->TicketObj->AdminCc;
my $group = RT::Group->new( $RT::SystemUser );
$group->LoadUserDefinedGroup(“NOC”);
$group->MemberEmailAddressesAsString;
$admincclist->AddMember($group->Id);

The problem is my code isn’t working and I don’t know why. Can anyone help me with it?


#2

What debugging have you done so far? Have got anything in the RT or webserver logs from running the scrip?


#3

so I have to ask you a dumb question… where can I find scrip error logs?


#4

It rather depends on how you’ve configured your web server and RT system. For the web server logs you might want to look in /var/log/httpd or /var/log/apache (depends on operating system and your configuration, and sort of assumes you’ve got a Linux/BSD/Unix type server with Apache on it) and see if you have something like error.log or ssl_error.log. For RT’s own debugging log it will depend what you have set for $LogToFile and $LogDir in your RT_SiteConfig.pm file.

If you don’t see any obvious error logging in any of these files (once you’ve found and/or configured them) you might want to slip some warn lines into your code temporarily just to let you see what things are triggered. For example I might start off with a couple of warnings in the custom condition to say which option was taken:

my $requestorsGroupObj = RT::Group->new($RT::SystemUser);
$requestorsGroupObj->LoadTicketRoleGroup(Type => ‘Requestor’, 
                                         Ticket => $self->TicketObj->id);
if( $self->TransactionObj->Type eq “Create” && 
    $requestorsGroupObj->LoadTicketRoleGroup(Type => ‘Requestor’, 
                                             Ticket => $self->TicketObj->id) eq “Agents”)
{
    warn "Agent requestor - returning true\n";
    return 1;
}
warn "Non-agent requestor - returning false\n";
return 0;

That way when you look in the logs during debugging you can see what choice was taken. If neither appeared, I’d be looking to see that the scrip was configured correctly as it wouldn’t be firing up. These warn statements can be removed once you’ve got it working.

One thing that has jumped out at me is that you’re using a numeric comparison when looking at the agent role group rather than eq string comparison.


#5

OK… so I tried hard and found out that in my RT version (4.4.1) there is nothing such “LoadTicketRoleGroup”. the problem is I am not good at coding at all.

can you guide me to write a scrip in custom condition part for this question: check if the requestor’s group is equal to “Agents” or not.


#6

First off I should point out that Best Practical offer consultancy services including custom development, which might be useful if you’re not a programmer and don’t have any coding staff locally.

Having said that, reading the documentation it appears LoadTicketRoleGroup method for RT::Group was deprecated some time ago and replaced by the generalised LoadRoleGroup method. This takes a parameter has with keys of Object and Name. So I think you’re code should look something like:

my $requestorsGroupObj = RT::Group->new($RT::SystemUser);
if( $self->TransactionObj->Type eq “Create” && 
    $requestorsGroupObj->LoadRoleGroup(Name => ‘Requestor’, 
                                       Object => $self->TicketObj) eq “Agents”)
{
    warn "Agent requestor - returning true\n";
    return 1;
}
warn "Non-agent requestor - returning false\n";
return 0;

Give that a go.


#7

Many thanks for your help!