Hi Mark (and Askar),
After reviewing my previous advice, I've changed my mind. This should be a
cleaner solution.
1. Don't mess with your templates.
2. I don't know whether _Set works with custom fields, so I'd use the
following to set your CF in the scrip I sent you. The scrip should
probably be a queue scrip, not global, unless you want to do this for all
your queues:
set_custom('noemail', "yes", 0);
### Sets custom field value
### Usage: set_custom($field_name, $field_value, $record_transaction)
sub set_custom {
my ($CFName, $CFValue, $record) = @_;
$record = $record ? 1 : 0;
my $cf = RT::CustomField->new($RT::SystemUser);
my ($id,$msg) = $cf->LoadByName(Name=>$CFName,);
if (!$id) {
$RT::Logger->debug("Error loading custom field '$CFName'");
return undef;
}
($id, $msg) = $Ticket->AddCustomFieldValue
(Field=>$cf, Value=>$CFValue, RecordTransaction=>$record);
}
3. Modify your Global Scrips #6 ("On Correspond Notify Requestors and Ccs
with template Correspondence") and #7 ("On Correspond Notify Other
Recipients with template Correspondence") and
a) change the Condition to User Defined; and
b) put the following code in the Custom condition area of both scrips:
{ ### True when transaction is incoming email and CF 'noemail' is not set
my $Transaction = $self->TransactionObj;
my $Ticket = $self->TicketObj;
my $val = $Transaction->Type eq "Correspond"
&& ! get_custom("noemail");
return $val;
### Returns custom field value
### get_custom($field_name)
sub get_custom {
my $target_name = $_[0];
my $val = $Ticket->FirstCustomFieldValue($target_name);
return $val if defined $val;
return undef;
}
}
So you should have 2 scenarios now with incoming email.
1. Email is from AdminCc and contains trigger word(s) in first line.
a) Your new scrip fires and sets the CF 'noemail' to 'yes', Owner to
email sender, Status to resolved
b) Global scrip #5 ("On Correspond Notify AdminCcs with template Admin
Correspondence") fires and sends mail to AdminCcs
c) Global scrips #6 and #7 do not fire because CF 'noemail' is set, so
no mail is sent to anyone else
2. Email is not from AdminCc or does not contain trigger word(s) in first
line:
a) Your new scrip does not fire because both conditions are not met, so
CF 'noemail' is not set
b) Global scrip #5 fires
c) Global scrips #6 and #7 fire because CF 'noemail' either doesn't
exist or is not set
Have fun!
Regards,
Gene
At 10:06 AM 11/27/2007, Mark Fuller wrote:
Ok I am very new to this so I added
$Ticket->_Set(Field => 'noemail', Value => 'yes', RecordTransaction => 0);
Now how do I tell the correspondence to look for that. And also if I change
the main script like that and I have the custom field set how do I get the
filed to be blank or no so that all future correspondence will work.
Again I am new to RT but we love it and are expanding it's use. I thought
about command by email but the CTO is concerned as am I with security and
this seems the safer way. Also we do want to comment via email
Mark Fuller
BandTel Engineering
603-528-6538 Option 2
603-528-6937 FAX
-----Original Message-----
From: Gene LeDuc [mailto:[EMAIL PROTECTED]
Sent: Monday, November 26, 2007 4:27 PM
To: Mark Fuller
Cc: [email protected]
Subject: RE: [rt-users] take and resolve actions via email
Hi Mark,
I'm not sure how you could change a correspondence transaction to a
comment. However...
If I wanted to just change the way that email is sent (only AdminCcs
getting an email), I'd add a custom field to the queue called
"NoCorrespond" and then modify the Correspondence template used for the "On
Correspond" scrip to include a check at the beginning to see if there is a
"NoCorrespond" field and whether it has anything in it. If so, exit the
template and don't send the email, otherwise proceed as usual. Then I'd
have the scrip I gave you put something into the "NoCorrespond" custom
field at the same time that it sets the owner and status. It's kind of
clunky and there are probably more elegant solutions, but I think it would
work. You might also want to make another scrip to send the mail to the
AdminCc when the "NoCorrespond" field gets something assigned to it (by
your other scrip), something like (I haven't tried this scrip, so it may
need work):
Condition: User Defined
Action: Notify AdminCcs as Comment
Template: Global template: Admin Comment
Custom condtion:
{ ### True on state change to "NoCorrespond"
my $Transaction = $self->TransactionObj;
my $val = $Transaction->Type eq "CustomField"
&& $Transaction->Field eq "NoCorrespond"
;
return $val;
}
Good luck!
Gene
At 12:00 PM 11/26/2007, Mark Fuller wrote:
>Thanks Gene it works great but.. Is there a way to make it a comment so
>only admin staff gets it
>
>Mark Fuller
>
>-----Original Message-----
>From: Gene LeDuc [mailto:[EMAIL PROTECTED]
>Sent: Monday, November 26, 2007 12:26 PM
>To: Mark Fuller
>Cc: [email protected]
>Subject: RE: [rt-users] take and resolve actions via email
>
>
>Hi Mark,
>
>Here's the scrip we use to resolve tickets via e-mail.
>
>In order to resolve a ticket this way, the e-mail must be from an
>AdminCc for that queue and it must contain the word "Ok" on the first
>line.
>
>Description: Resolved by e-mail
>Condition: User Defined
>Action: User Defined
>Template: Global template: Blank
>Stage: TransactionCreate
>
>Custom condition:
>{ ### True if e-mail contains 'ok' - sets owner, resolves ticket
> my $Transaction = $self->TransactionObj;
> my $CreatorId = $Transaction->CreatorObj->Id;
> my $Queue = $self->TicketObj->QueueObj;
> my $val = $Transaction->Type eq 'Correspond'
> && $Queue->IsAdminCc($CreatorId)
> && $Transaction->Content =~ /\bok\s/i;
> return $val;
>}
>
>Custom action prep code:
>return 1;
>
>Custom action cleanup code:
>### Set Set owner to e-mail sender, status to 'resolved'
>my $Ticket = $self->TicketObj;
>my $Transaction = $self->TransactionObj;
>my $CreatorId = $Transaction->CreatorObj->Id;
>$Ticket->_Set(Field=>'Owner', Value=>$CreatorId, RecordTransaction=>0);
>$Ticket->_Set(Field => 'Status', Value => 'resolved', RecordTransaction
>=> 0);
>
>The 2 lines at the end of the cleanup code could also be:
> $Ticket->SetOwner($CreatorId);
> $Ticket->SetStatus('resolved');
>but I use _Set instead because I don't want to fire off any more
>transactions when I resolve tickets this way.
>
>Regards,
>Gene
--
Gene LeDuc, GSEC
Security Analyst
San Diego State University
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
SAVE THOUSANDS OF DOLLARS ON RT SUPPORT:
If you sign up for a new RT support contract before December 31, we'll take
up to 20 percent off the price. This sale won't last long, so get in touch
today.
Email us at [EMAIL PROTECTED] or call us at +1 617 812 0745.
Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]
Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com