[rt-users] Scrip help needed
Brumm, Torsten / Kuehne + Nagel / Ham MI-ID
torsten.brumm at Kuehne-Nagel.com
Thu Sep 24 10:48:19 EDT 2009
Hi Ruslan, Raed,
thanks for your support, it is working well now.
Attached again the correct working scrip action, if someone else has a need for this:
my $Clone = $self->TicketObj;
my $note;
my $t = $self->TicketObj->Transactions;
$t->Limit( FIELD => 'Type', VALUE => 'Correspond' );
$t->OrderByCols (
{ FIELD => 'Created', ORDER => 'DESC' },
{ FIELD => 'id', ORDER => 'DESC' },
);
my $CommentObj = $t->First;
if( $CommentObj && $CommentObj->id ) {
$note = $CommentObj->Content;
};
my $Actor = $self->TransactionObj->Creator;
my $user = RT::User->new($RT::SystemUser);
$user->Load($Actor);
my $Name = $user->Name;
while (my $related = $Clone->ReferredToBy->Next) {
my $original = $Clone->id;
my $reply_will_be_on = RT::Ticket->new($user);
$reply_will_be_on->Load( $related->BaseObj->id );
$reply_will_be_on->Comment( Content => $self->loc( "Information added by [_1].", # loc
$Name,
) . "\n" . $self->loc( "Notes: [_1]", # loc
$note
),
);
}
return 1;
Kuehne + Nagel (AG & Co.) KG, Geschaeftsleitung: Hans-Georg Brinkmann (Vors.), Dirk Blesius (Stellv.), Reiner Heiken (Stellv.), Bruno Mang, Alfred Manke, Christian Marnetté (Stellv.), Mark Reinhardt (Stellv.), Jens Wollesen, Rainer Wunn, Sitz: Bremen, Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Persoenlich haftende Gesellschaft: Kuehne & Nagel A.G., Sitz: Contern/Luxemburg Geschaeftsfuehrender Verwaltungsrat: Klaus-Michael Kuehne
-----Urspruengliche Nachricht-----
Von: Ruslan Zakirov [mailto:ruslan.zakirov at gmail.com]
Gesendet: Donnerstag, 24. September 2009 16:15
An: Brumm, Torsten / Kuehne + Nagel / Ham MI-ID
Cc: Raed El-Hames; rt-users at lists.bestpractical.com
Betreff: Re: [rt-users] Scrip help needed
$self->TransactionObj->Creator returns id not a user object, when you need object.
On Thu, Sep 24, 2009 at 5:52 PM, Brumm, Torsten / Kuehne + Nagel / Ham MI-ID <torsten.brumm at kuehne-nagel.com> wrote:
> Hi Ruslan,
>
> thanks for the hint. tried it with this piece of code:
>
> my $Clone = $self->TicketObj;
> my $note;
> my $t = $self->TicketObj->Transactions;
> $t->Limit( FIELD => 'Type', VALUE => 'Correspond' );
> $t->OrderByCols (
> { FIELD => 'Created', ORDER => 'DESC' },
> { FIELD => 'id', ORDER => 'DESC' },
> );
> my $CommentObj = $t->First;
> if( $CommentObj && $CommentObj->id ) {
> $note = $CommentObj->Content;
> };
> my $Actor = $self->TransactionObj->Creator;
>
> while (my $related = $Clone->ReferredToBy->Next) {
> my $original = $Clone->id;
> my $relid = $related->BaseObj->id;
> my $reply_will_be_on = RT::Ticket->new( $Actor );
> $reply_will_be_on->Load( $related->BaseObj->id );
> $reply_will_be_on->Comment( Content => $self->loc(
> "Information added by [_1].", # loc
> $Actor,
> ) .
> "\n" . $self->loc( "Notes: [_1]", # loc
> $note
> ),
> ); } return 1;
>
>
> this ends up with:
>
> [Thu Sep 24 13:47:26 2009] [error]: Scrip 1159 Commit failed: Can't call method "UserObj" on an undefined value at /opt/rt3/lib/RT/Ticket_Overlay.pm line 3647.
>
> OK, line 3647 from Ticket_Overlay:
>
> $self->HasRight(
> Principal => $self->CurrentUser->UserObj(),
> Right => "$right"
> )
> );
>
>
> OK, i'm working as superuser, so i should have the right....digging in
> the dark :-(
>
>
> -----Urspruengliche Nachricht-----
> Von: Ruslan Zakirov [mailto:ruslan.zakirov at gmail.com]
> Gesendet: Donnerstag, 24. September 2009 15:23
> An: Brumm, Torsten / Kuehne + Nagel / Ham MI-ID
> Cc: Raed El-Hames; rt-users at lists.bestpractical.com
> Betreff: Re: [rt-users] Scrip help needed
>
> Torsten,
>
> Scrips work under system user, but you have to reload ticket as creator of the transaction. Something like:
> ...
> my $reply_will_be_on = RT::Ticket->new( $txn->CreatorObj ); $reply_will_be_on->Load( $ticket_you_found_as_system_user->id ); $reply_will_be_on->Comment(...); ...
>
> On Thu, Sep 24, 2009 at 2:39 PM, Brumm, Torsten / Kuehne + Nagel / Ham MI-ID <torsten.brumm at kuehne-nagel.com> wrote:
>> Hi Roy,
>> no success, still: RT_System - Comments added
>>
>> :-(
>>
>> Thanks
>>
>> Torsten
>>
>>
>> Kuehne + Nagel (AG & Co.) KG, Geschaeftsleitung: Hans-Georg Brinkmann
>> (Vors.), Dirk Blesius (Stellv.), Reiner Heiken (Stellv.), Bruno Mang,
>> Alfred Manke, Christian Marnetté (Stellv.), Mark Reinhardt (Stellv.),
>> Jens Wollesen, Rainer Wunn, Sitz: Bremen, Registergericht: Bremen,
>> HRA 21928, USt-IdNr.: DE 812773878, Persoenlich haftende Gesellschaft:
>> Kuehne & Nagel A.G., Sitz: Contern/Luxemburg Geschaeftsfuehrender
>> Verwaltungsrat: Klaus-Michael Kuehne
>>
>>
>>
>> -----Urspruengliche Nachricht-----
>> Von: Raed El-Hames [mailto:rfh at vialtus.com]
>> Gesendet: Donnerstag, 24. September 2009 11:59
>> An: Brumm, Torsten / Kuehne + Nagel / Ham MI-ID
>> Cc: rt-users at lists.bestpractical.com
>> Betreff: Re: [rt-users] Scrip help needed
>>
>> Hi Torsten;
>>
>> Try
>>
>> $related->BaseObj->Comment(
>> Creator => $self->TransactionObj->Creator,
>> Content => $self->loc( "Information added by [_1].", # loc
>> $self->TransactionObj->CreatorObj->Name,
>> ) . "\n" . $self->loc( "Notes: [_1]", # loc
>> $note
>> ),
>> );
>>
>>
>> Note the Creator line I added.
>>
>> Regards;
>> Roy
>>
>> Brumm, Torsten / Kuehne + Nagel / Ham MI-ID wrote:
>>> Hi,
>>> i'm trying to write a scrip which does the following:
>>>
>>> We have two or more tickets, each ticket has a refersto to another
>>> like this:
>>>
>>> #1 -> refers to #2
>>>
>>> Now, if someone at ticket #2 writes an update, this update (reply in
>>> our case) should be posted also to ticket #1
>>>
>>> Till this point it is working fine, now my problem:
>>>
>>> The Update on Ticket #1 is done by RT_System (from the scrip) after
>>> the user in ticket #2 writes an update and i have no idea at the
>>> moment, how can i do the update as the user, doing the reply on
>>> ticket
>>> #2 ?!?
>>>
>>> The Part of the source writing back the update:
>>>
>>> $related->BaseObj->Comment(
>>> Content => $self->loc( "Information added by [_1].", # loc
>>> $self->TransactionObj->CreatorObj->Name,
>>> ) . "\n" . $self->loc( "Notes: [_1]", # loc
>>> $note
>>> ),
>>> );
>>> I'm not sure how can i add the actual actor from Ticket #2 inside
>>> this part of code?!?
>>>
>>> Below is my full source till now:
>>>
>>> my $Clone = $self->TicketObj;
>>> my $note;
>>> my $t = $self->TicketObj->Transactions; $t->Limit( FIELD => 'Type',
>>> VALUE => 'Correspond' ); $t->OrderByCols (
>>> { FIELD => 'Created', ORDER => 'DESC' },
>>> { FIELD => 'id', ORDER => 'DESC' },
>>> );
>>> my $CommentObj = $t->First;
>>> if( $CommentObj && $CommentObj->id ) { $note =
>>> $CommentObj->Content; }; # Get the actual Actor of this transaction
>>> my $Actor = $self->TransactionObj->Creator; # $Actor has the ID of
>>> the actual Transaction my $temp_user = RT::User->new();
>>> $temp_user->Load($Actor); my $AName = $temp_user->Name(); # Name of
>>> Actor in acutal Transaction
>>> - possibly not needed
>>>
>>> while (my $related = $Clone->ReferredToBy->Next) {
>>> my $original = $Clone->id;
>>> my $relid = $related->BaseObj->id;
>>> $related->BaseObj->Comment(
>>> Content => $self->loc( "Information added by [_1].", # loc
>>> $self->TransactionObj->CreatorObj->Name,
>>> ) . "\n" . $self->loc( "Notes: [_1]", # loc
>>> $note
>>> ),
>>> );
>>> }
>>> return 1;
>>>
>>> Any help is appriciated.
>>>
>>> Torsten
>>>
>>> Kuehne + Nagel (AG & Co.) KG, Geschaeftsleitung: Hans-Georg
>>> Brinkmann (Vors.), Dirk Blesius (Stellv.), Reiner Heiken (Stellv.),
>>> Bruno Mang, Alfred Manke, Christian Marnetté (Stellv.), Mark
>>> Reinhardt (Stellv.), Jens Wollesen, Rainer Wunn, Sitz: Bremen,
>>> Registergericht: Bremen, HRA 21928, USt-IdNr.: DE 812773878, Persoenlich haftende Gesellschaft:
>>> Kuehne & Nagel A.G., Sitz: Contern/Luxemburg, Geschaeftsfuehrender
>>> Verwaltungsrat: Klaus-Michael Kuehne
>>>
>>>
>>
>> _______________________________________________
>> http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>>
>> Community help: http://wiki.bestpractical.com Commercial support:
>> sales at bestpractical.com
>>
>>
>> Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>> Buy a copy at http://rtbook.bestpractical.com
>>
>
>
>
> --
> Best regards, Ruslan.
>
--
Best regards, Ruslan.
More information about the rt-users
mailing list