Customized Subject in Reply Emails

Moderator: crythias

Locked
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Customized Subject in Reply Emails

Post by iwanschmid »

hi

i want do customize the subject of reply emails with a dynamicfield.

i found the file "Ticket.pm". there is a function that generates the subject. the function is called "TicketSubjectBuild"

how can i access a dynamic field from the ticket in this function?

at the moment it looks like this:

Code: Select all

return $TicketSubjectRe . "[$TicketHook$TicketHookDivider$Param{TicketNumber}] " . $Subject;
and i like to enhance it like this:

Code: Select all

return $TicketSubjectRe . "[$TicketHook$TicketHookDivider$Param{TicketNumber}] " . $DynamicField_Fremdnummer . " - " . $Subject;
but i have no idea how i can get a value for the dynmic field "DynamicField_Fremdnummer".

can anyone help me?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

Hello and welcome to the forum.

I doubt that what you are doing is the most practical way. It's probably easier with javascript in the template.

Anyhow, to answer your question:

The Param only contains the ticketnumber and the subject. Thus you have to first search for the ticket id:

Code: Select all

my @TicketIDs = $TicketObject->TicketSearch(
       # result (required)
       Result => 'ARRAY',

       # ticket number (optional) as STRING or as ARRAYREF
       TicketNumber => $Param{TicketNumber},
);
Then "get" the ticket, with DFs:

Code: Select all

   my %Ticket = $TicketObject->TicketGet(
       TicketID      => $TicketIDs[0],
       DynamicFields => 1,
       UserID        => 1,
   );
Then you should (untested) get the DF-value via:

Code: Select all

$Ticket{DynamicField_NameOfYourField}
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Re: Customized Subject in Reply Emails

Post by iwanschmid »

thank you very much for the fast answer :-)

i think i undestand, what these code does. and it's exactly what i look for.

Code: Select all

	my @TicketIDs = $TicketObject->TicketSearch(
       Result => 'ARRAY',
       TicketNumber => $Param{TicketNumber},
	);
	my %Ticket = $TicketObject->TicketGet(
       TicketID      => $TicketIDs[0],
       DynamicFields => 1,
       UserID        => 1,
	);
but when i paste this to my ticket.pm i get the following error message:
Global symbol "$TicketObject" requires explicit package name at C:/otrs/OTRS/bin/cgi-bin/../../Kernel/System/Ticket.pm line 830.

do you have an idea why?
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

Yup. That specific subroutine does not have the TicketObject. Following the API here:
http://otrs.perl-services.de/docs/otrs/ ... icket.html
you would get that via

Code: Select all

my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
Also, the TicketSearch has probably more mandatory params, at least the UserID has to be given.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Re: Customized Subject in Reply Emails

Post by iwanschmid »

hi again! i'm very thankful for your help! :-)

when i add the following line to ticket.pm i get an error from the webserver:

Code: Select all

my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
Error Message:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

Apache error log should tell you what's wrong.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Re: Customized Subject in Reply Emails

Post by iwanschmid »

Can't call method "Get" on an undefined value at C:/otrs/OTRS/bin/cgi-bin/../../Kernel/System/Ticket.pm line 809., referer: http://otrs.flachglas.ch/otrs/index.pl? ... etID=10320
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

It seems you don't find tickets with a certain ticketnumber (even though that value should be set).

I would suggest you stop trying to modify the file as you clearly lack experience with perl. You might try to change the subject with javascript in the template, if you have more experience with JS.
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Re: Customized Subject in Reply Emails

Post by iwanschmid »

now it works :-)

Code: Select all

	my @TicketIDs = $Self->TicketSearch(
       Result => 'ARRAY',
       TicketNumber => $Param{TicketNumber},
       UserID     => 1,
	   );
	my %Ticket = $Self->TicketGet(
       TicketID      => $TicketIDs[0],
       DynamicFields => 1,
       UserID        => 1,
	);
thank you very much for your help :-)
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

What did you change? Only the UserID Param?
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
iwanschmid
Znuny newbie
Posts: 6
Joined: 08 Oct 2015, 14:24
Znuny Version: 5.0.13
Real Name: Iwan Schmid
Company: Flachglas (Schweiz) AG

Re: Customized Subject in Reply Emails

Post by iwanschmid »

i just replaced "$TicketObject" with "$Self" and added the line "UserID => 1,", beause UserID ist required for "TicketSearch":

Your Code:

Code: Select all

   my @TicketIDs = $TicketObject->TicketSearch(
       Result => 'ARRAY',
       TicketNumber => $Param{TicketNumber},
   );
   my %Ticket = $TicketObject->TicketGet(
       TicketID      => $TicketIDs[0],
       DynamicFields => 1,
       UserID        => 1,
   );
Working Code:

Code: Select all

   my @TicketIDs = $Self->TicketSearch(
       Result => 'ARRAY',
       TicketNumber => $Param{TicketNumber},
       UserID     => 1,
      );
   my %Ticket = $Self->TicketGet(
       TicketID      => $TicketIDs[0],
       DynamicFields => 1,
       UserID        => 1,
   );
RStraub
Znuny guru
Posts: 2210
Joined: 13 Mar 2014, 09:16
Znuny Version: 6.0.14
Real Name: Rolf Straub

Re: Customized Subject in Reply Emails

Post by RStraub »

Hah, good point. Never worked on the Object itself hehe...
Currently using: OTRS 6.0.14 -- MariaDB -- Ubuntu 16 LTS
Locked