- $RT::Handle->BeginTransaction;
- my $old_owner_id = $self->TicketObj->_Value('Owner');
- $RT::Logger->debug(qq{EJR-SetOwner: old owner is "$old_owner_id".});
- my $subject = $self->TicketObj->Subject;
- if ($subject =~ s{A (w+):? s+ (?:FW|RE): s* }{}ix )
- {
- my $new_owner_name = $1;
- $RT::Logger->debug(qq{EJR-SetOwner: new owner name is "$new_owner_name".});
- my $new_owner_obj = RT::User->new($self->CurrentUser);
- $new_owner_obj->Load($new_owner_name);
- my $new_owner_id = $new_owner_obj->Id or do
- {
- $RT::Logger->error(qq{EJR-SetOwner: Cannot load User "$new_owner_name".});
- $RT::Handle->Rollback;
- return (0, qq{User "$new_owner_name" does not exist.});
- };
- $RT::Logger->debug(qq{EJR-SetOwner: User id for $new_owner_name is $new_owner_id.});
- # Set the new owner
- my ($rv,$msg) = $self->TicketObj->_Set(Field => 'Owner',
- Value => $new_owner_id,
- RecordTransaction => 0,
- CheckACL => 0);
- unless ($rv)
- {
- $RT::Logger->error(qq{Cannot assign ticket to "$new_owner_name": $msg});
- $RT::Handle->Rollback;
- return (0, qq{Cannot assign ticket to "$new_owner_name": $msg});
- }
- my $oid = $self->TicketObj->Owner;
- $RT::Logger->debug(qq{EJR-SetOwner: Assigned owner ($oid).});
- # Change the subject line
- ($rv,$msg) = $self->TicketObj->_Set(Field => 'Subject',
- Value => $subject,
- RecordTransaction => 0,
- CheckACL => 0);
- unless ($rv)
- {
- $RT::Logger->warning(qq{Cannot change ticket subject to "$subject": $msg});
- $RT::Handle->Rollback;
- return (0, 'Cannot change ticket subject');
- }
- $RT::Handle->Commit;
- $RT::Logger->debug(qq{EJR-SetOwner: Assigned subject.});
- }
- else
- {
- $RT::Logger->error(qq{Cannot parse ticket subject "$subject"});
- $RT::Handle->Rollback;
- return (0, 'Cannot parse ticket subject');
- }
- $RT::Logger->debug(qq{EJR-SetOwner: Success, apparently.});
- return 1;
Scrip to assign user
By: Sue D. Nymme | Date: Jan 5 2011 20:23 | Format: None | Expires: never | Size: 2.17 KB | Hits: 1540
Latest pastes
3 hours ago
1 days ago
2 days ago
2 days ago
3 days ago