How to write a scrip to change status to 'rejected' upon ticket creation

Hi,

I need to create a scrip that will set the status to “rejected” upon creation of the ticket whenever the domain name is not part of a specific domain name. Let’s say that our own domain name is mycompany.org, we want all the tickets not coming from *mycompany.org and *gmail.com to have a “rejected” status upon creation.

Maybe there’s something already out there that is similar to what I need.

Thx in advance.

Hi,

There is a way to do this by writing a scrip, but it would be easier to move the email to a folder that is not monitored by RT in the mailbox, using some kind of mailbox rule.This way, you can use already implemented rules to do the same thing.

Hi Ivancni,

in RT the ticket will be created, anyway. After that you can set the status ‘rejected’. Depending on your Scrips there will be emails to Requestor and Watcher on creation and on rejecting.

So @ALone is right, maybe a mailbox with automatic answer (vacation) is easier.

If you want to do it in RT you need a script ‘OnCreate’ with Action ‘User Defined

Here’s an idea of code, not tested.

Custom preparation:

my $ticket = $self->TicketObj;
my $log_tag = $ticket->QueueObj->Name . "[YourTag#" . $ticket->id . "]: "; 
my $requestor_address = $self->TicketObj->RequestorAddresses;

# Test if requestor is in blocked domain
if( $requestor_address =~ m/.*\@gmail.com/im ) 
{ 
	$RT::Logger->info($log_tag . "found requestor \@gmail.com, going on");
	$RT::Logger->info($log_tag . $requestor_address);
	return 1 
}
else 
{ 
	$RT::Logger->info($log_tag . "Did not find \@gmail.com, leaving Scrip");
	$RT::Logger->info($log_tag . $requestor_address);
	return 0;
};

Custom action code:

# Do logging as needed, copy from above
$self->TicketObj()->setStatus('rejected');
return 1;

Hope it helps.

regards, Andre.