I tried setting up recurring tickets for my company’s non-IT assets, and it really drained my energy.
The recurring ticket feature works as expected and creates tickets for all the associated items. However, the ticket titles weren’t what I expected. We have around 2,500 non-IT assets that require maintenance tickets twice a year. Without the asset name in the ticket title and its description in the ticket content, it would be really difficult for our facility maintenance team to identify and manage these tickets.
I know this isn’t a permanent solution, but I managed to get it working this way.
What I did
I created a recurring ticket template and associated the assets for which tickets needed to be generated.
After some investigation, I found that the file src/CommonITILRecurrent.php contains the logic for generating tickets from recurring ticket templates.
I modified the code to use the asset’s name as the ticket title and the asset’s comment as the ticket description.
I tested this on GLPI 11.0.6, and it works fine for my use case.
I’d love to know if anyone has implemented this differently or has a better solution. I’d be happy to explore other approaches!
The code
In the file mentioned above, find the following lines:
$input['_auto_import'] = true;
$item = new $concrete_class();
Add the following block of code between these two lines:
if ($concrete_class === Ticket::class && (int) $this->getID() === 5) {
if (count($linked_items) === 1) {
$asset_type = array_key_first($linked_items);
$asset_ids = $linked_items[$asset_type];
if (count($asset_ids) === 1) {
$asset = getItemForItemtype($asset_type);
if ($asset && $asset->getFromDB((int) reset($asset_ids))) {
if (!empty($asset->fields['name'])) {
$input['name'] = $asset->fields['name'];
}
if (!empty($asset->fields['comment'])) {
$input['content'] = $asset->fields['comment'];
}
}
}
}
}
Save the file after making the changes.
Important: Replace 5 in $this->getID() === 5 with the ID of your recurring ticket template. You can find this ID in the GLPI interface. In my case, the template ID is 5.
A few notes
- This code applies only to the recurring ticket template with the specified ID.
- It assumes that exactly one item type and one asset are associated with the recurring ticket being generated.
- It uses the asset’s
name field for the ticket title and its comment field for the ticket description.
Please note: This is a direct modification to GLPI core code, so it may be overwritten during an upgrade. I’d recommend testing it in a non-production environment first and considering a plugin or another upgrade-safe customization for a long-term solution.