i have 10 custom fileds and all are ok showing in body ,
i would like to add only one off them to header in pdf

this is code
i would like to show only filed id="field_73"
any help would be great
thank you all
<?php
foreach (DynamicFormEntry::forTicket($ticket->getId()) as $form) {
// Skip core fields shown earlier in the ticket view
$answers = $form->getAnswers()->exclude(Q::any(array(
'field__flags__hasbit' => DynamicFormField::FLAG_EXT_STORED,
'field__name__in' => array('subject', 'priority')
)));
if (count($answers) == 0)
continue;
?>
<table class="custom-data" cellspacing="0" cellpadding="4" width="100%" border="0">
<tr><td colspan="2" class="headline flush-left"><?php echo $form->getTitle(); ?></th></tr>
<?php foreach($answers as $a) {
if (!($v = $a->display())) continue; ?>
<tr>
<th><?php
echo $a->getField()->get('label');
?>:</th>
<td><?php
echo $v;
?></td>
</tr>
<?php } ?>
</table>
<?php
$idx++;
} ?>

Can you read the contents of a field from a database using SQL?
If so, just add the code to ticket-print.tmpl.php.
I recommend using include, which will make your work easier during the next update.

Thank you.
I was trying to acces custom field that is generated in os.

or what variable in ticket-print.tmpl.php is for EnteryID.

Thank you

Find the ticket ID ($ticket->getId()) in the ticket-print.tmpl.php file.
Search for the ticket ID in the ost_form_entry table in the object_id column. This will get the ID from the id column.
Search this ID in the _ost_form_entry_values__ table in the entry_id column. This will get the value you are looking for from the value column.

<?php
$sql = "SELECT ost_form_entry_values.value FROM ost_ticket JOIN ost_form_entry ON ost_ticket.ticket_id = ost_form_entry.object_id JOIN ost_form_entry_values ON ost_form_entry.id=ost_form_entry_values.entry_id WHERE ost_ticket.number = '21000165' and ost_form_entry_values.field_id = '73'";
$result = mysql_query($sql);
for
echo [$result];
?>

when i run querry in phpmyadmin i get corect value but in php i get error.

Create a directory at the root named MyScripts.

Create the PrintField.inc.php file here

Paste following code into the PrintField.inc.php file

<?php
$server="localhost";
$username="name";
$passwort="password";
$dbname="database-name";
$FieldID="73";

/////////////////////////////////////////////////////////////////////////////////////////

//Set connection with database
$connection = mysqli_connect($server,$username,$passwort);
if (!$connection) die ("Not connected with MySQL");

$table=mysqli_select_db($connection, $dbname);
mysqli_query($connection, "set names utf8"); 
if(!@table) die ("Not connected to database."); 

/////////////////////////////////////////////////////////////////////////////////////////

//Get ticket ID from osTicket
$TicketID = $ticket->getId();

//Read value from table ost_form_entry into variable
if(!$result = mysqli_query($connection, "SELECT * FROM ost_form_entry WHERE object_id=\"$TicketID\"")) {echo "<h2>Not connected with table ost_form_entry.</h2>\n"; }
while($ost_form_entry = mysqli_fetch_array($result))
	{
		 $EntryID = $ost_form_entry["id"];
	}

//Read value from table ost_form_entry_values into variable
if(!$result = mysqli_query($connection, "SELECT * FROM ost_form_entry_values WHERE entry_id=\"$EntryID\" AND field_id=\"$FieldID\"")) {echo "<h2>Not connected with table ost_form_entry_values.</h2>\n"; }
while($ost_form_entry_values = mysqli_fetch_array($result))
	{
		 $EntryValue = $ost_form_entry_values["value"];
	}

mysqli_close($connection);

/////////////////////////////////////////////////////////////////////////////////////////

//Display in ticket-print.tmpl.php
?>
<tr>
	<th><?php echo __('Your value'); ?></th>
	<td><?php echo $EntryValue; ?></td>
</tr>

Edit the lines at the beginning of the file as needed.

Add
<?php include(ROOT_DIR.'MyScripts/PrintField.inc.php'); ?>
to the file \include\staff\templates\ticket-print.tmpl.php

Of course, it's not perfect. You have to fine-tune yourself.

You would also want to post the PHP error that you get so someone can narrow down what is wrong.

Write a Reply...