dps
December 18, 2019, 11:03am
1
Good Day
I am trying to perform an action using Perl and also attach HTML Formatted Ticket Information.
Perl Part
To: { my $ticket = $Ticket;
my $name = '';
my $cfName = '';
my $ticketcfValue = '';
my $cfValues = '';
my $val = 'not set';
my $CustomFields = $ticket->QueueObj->TicketCustomFields();
while (my $CustomField = $CustomFields->Next())
{
$name = $CustomField->Name;
if ($name eq 'Allocated To')
{
# get the currently selected Resolver name
$ticketcfValue = $ticket->CustomFieldValuesAsString($name);
# load all the possible values for Resolver Names
my $cf = RT::CustomField->new(RT::SystemUser);
$cf->LoadByName(Name => 'Allocated To');
my $cfValues = $cf->Values;
while (my $cfValue = $cfValues->Next)
{
if ($cfValue->Name eq $ticketcfValue)
{
$val = $cfValue->Description;
}
}
}
}
$val; }
After the above action I would like to send ticket information in HTML Format
HTML Part
<p>Greetings,</p>
<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>
<hr/>
<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
If I add Content Type: text/html on the beginning of the template then the perl part does not work.
How do I combine the two?
knation
December 18, 2019, 11:29am
2
Does that Perl bit work when testing without the text/html line?
So this is all one template? And you’re saying its not working if you just add the line
Content-type: text/html
to the top of the template? What happens if you put the Content-type
line after the To:
?
knation
December 18, 2019, 11:33am
4
I assume you need to use the $OUT
variable in that Perl block right?
dps
December 18, 2019, 1:00pm
5
@knation yes the Perl bit works without the text/html line.
dps
December 18, 2019, 1:03pm
6
@GreenJimll It is one Template.
I tried to put it below To:
To:
Content-Type: text/html
{ my $ticket = $Ticket;
my $name = '';
my $cfName = '';
my $ticketcfValue = '';
my $cfValues = '';
my $val = 'not set';
my $CustomFields = $ticket->QueueObj->TicketCustomFields();
while (my $CustomField = $CustomFields->Next())
{
$name = $CustomField->Name;
if ($name eq 'Allocated To')
{
# get the currently selected Resolver name
$ticketcfValue = $ticket->CustomFieldValuesAsString($name);
# load all the possible values for Resolver Names
my $cf = RT::CustomField->new(RT::SystemUser);
$cf->LoadByName(Name => 'Allocated To');
my $cfValues = $cf->Values;
while (my $cfValue = $cfValues->Next)
{
if ($cfValue->Name eq $ticketcfValue)
{
$val = $cfValue->Description;
}
}
}
}
$val; }
<p>Greetings,</p>
<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>
<hr/>
<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" }
It does not work.
dps
December 18, 2019, 1:04pm
7
@knation how do I add the $OUT to the perl block?
knation
December 18, 2019, 1:05pm
8
Each header needs its own line, you are putting the “To:” as “Content-Type: text/html…” in your example you just posted. Make the first line the content type then the next one the “To” block
dps
December 18, 2019, 1:08pm
9
Content-Type: text/html
<p>Greetings,</p>
<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>
<hr/>
<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" }
To: { my $ticket = $Ticket;
my $name = '';
my $cfName = '';
my $ticketcfValue = '';
my $cfValues = '';
my $val = 'not set';
my $CustomFields = $ticket->QueueObj->TicketCustomFields();
while (my $CustomField = $CustomFields->Next())
{
$name = $CustomField->Name;
if ($name eq 'Allocated To')
{
# get the currently selected Resolver name
$ticketcfValue = $ticket->CustomFieldValuesAsString($name);
# load all the possible values for Resolver Names
my $cf = RT::CustomField->new(RT::SystemUser);
$cf->LoadByName(Name => 'Allocated To');
my $cfValues = $cf->Values;
while (my $cfValue = $cfValues->Next)
{
if ($cfValue->Name eq $ticketcfValue)
{
$val = $cfValue->Description;
}
}
}
}
$val; }
Do you mean like this?
No, you’re splitting the headers and body now. All the headers need to be at the top.
G.Booth
December 18, 2019, 1:13pm
11
Content-Type: text/html
To:
HTML
regards
Garry
dps
December 18, 2019, 1:15pm
12
Content-Type: text/html
To:
{ my $ticket = $Ticket;
my $name = '';
my $cfName = '';
my $ticketcfValue = '';
my $cfValues = '';
my $val = 'not set';
my $CustomFields = $ticket->QueueObj->TicketCustomFields();
while (my $CustomField = $CustomFields->Next())
{
$name = $CustomField->Name;
if ($name eq 'Allocated To')
{
# get the currently selected Resolver name
$ticketcfValue = $ticket->CustomFieldValuesAsString($name);
# load all the possible values for Resolver Names
my $cf = RT::CustomField->new(RT::SystemUser);
$cf->LoadByName(Name => 'Allocated To');
my $cfValues = $cf->Values;
while (my $cfValue = $cfValues->Next)
{
if ($cfValue->Name eq $ticketcfValue)
{
$val = $cfValue->Description;
}
}
}
}
$val; }
<p>Greetings,</p>
<p>A new incident has been created: <b>{$Ticket->Subject()}</b>.</p>
<hr/>
<table border="0">
<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr>
<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr>
{ ($Ticket->FirstCustomFieldValue('Severity')) ? "<tr><td align='right'><b>Severity:</b></td><td>".$Ticket->FirstCustomFieldValue('Severity')."</td></tr>\n" : "" }
This does not work.
The to
section is meant to send out an email to the custom field populated with a mail address.
When trying it out the above way it does not work.
@G.Booth
I tried that and it does not work.
I tried the HTML First and Perl after with that set as the header and vice versa.
The To:
and the open brace need to be on the same line, as your Perl is supposed to be generating the email address (I assume that’s what its trying to do at least!).
dps
December 18, 2019, 1:21pm
15
@knation @GreenJimll Thank you guys for always assisting !!!