AddCustomFieldsValuesToMail
Jump to navigation
Jump to search
This Template part adds ticket custom field values to mail.
{ # old RT versions may be need: # my $CustomFields = $Ticket->QueueObj->CustomFields(); my $CustomFields = $Ticket->QueueObj->TicketCustomFields(); while (my $CustomField = $CustomFields->Next()) { my $CustomFieldValues=$Ticket->CustomFieldValues($CustomField->Id); $OUT .= $CustomField->Name; if ($CustomFieldValues->Count) { my $spacer; if ( $CustomField->Type ne 'FreeformMultiple' and $CustomField->Type ne 'SelectMultiple' ) { $spacer = " " x (20 - length($CustomField->Name)); } else { $spacer = "\n"; } $OUT .= ":" . $spacer; } else { $OUT .= ":\n"; next; } while (my $CustomFieldValue = $CustomFieldValues->Next) { $OUT .= " " if ( $CustomField->Type eq 'FreeformMultiple' or $CustomField->Type eq 'SelectMultiple' ); $OUT .= $CustomFieldValue->Content . "\n"; } $OUT .= "\n" if ( $CustomField->Type eq 'FreeformMultiple' or $CustomField->Type eq 'SelectMultiple' ); } $OUT; }
This works for Ticket Level custom fields. This will not list Transaction Custom Fields.
In order to access Transaction Custom fields e. g. in a Template, it is necessary to enable the TransactionBatch stage. If this is not enabled, a script might trigger a Template at a point in time when the custom field is not yet available because it had not been processed yet.
The following worked for me (Debian, rt 3.4.1, to include a Transaction custom field in a template that is triggered by a scrip running on "TransactionBatch".
my $OwnCustomFieldValue; my $ViValue; my $TicketObj = $Ticket; my $OwnObjectCustomFields = $TicketObj->Transactions; $OwnContent = $Transaction; $OwnCustomFieldValue=$OwnContent->CustomFieldValues; while (my $SingleOwnCustomFieldValue = $OwnCustomFieldValue->Next) { $ViValue=$SingleOwnCustomFieldValue->Content; $RT::Logger->debug( "> CustomField: $ViValue <<<<<<<< \n\n" ); }
I assume that it is also possible to access custom-field name via CustomField->Name and the custom-field type via CustomField->Type.