Jump to content

Adding custom fields to support ticket emails


Recommended Posts

I saw this was asked a while ago, but no response was ever given, so just wondered if things have been updated since.

In some departments I collect a number of custom fields, so it would be really helpful if these could be added to the ticket alert email that's sent out to staff - this way they don't need to load up whmcs just to check for the info.

Is this possible? Or as with seemingly everything I need, I'll need to write an extra hook for it 😭

Link to comment
Share on other sites

  • WHMCS Staff

Hi @bendrop,

Thanks for posting!

This is absolutely possible however would require some custom logic. You'd need to use the EmailPreSend hook to create extra variables to use within the Email Template.

For example, you could use the following code which would replace {$demo} in your Email Template with "Hello World!":

<?php

add_hook('EmailPreSend', 1, function($vars) {
    $merge_fields = [];
    $merge_fields['demo'] = "Hello World!";
    return $merge_fields;
});

More information on this is available at https://docs.whmcs.com/Email_Templates#Custom_PHP_Logic

Link to comment
Share on other sites

5 hours ago, WHMCS Peter said:

As long as it's a ticket notification, yes. The relid value would be the tbltickets.id value. Correct.

Omg, that was the most horrible hour I just spent going around and around in a loop until I thought to actually check the relid value.

For the template "Support Ticket Change Notification" (the alert sent to the staff) - the relid is BLANK!

Wish I had thought to check that first! So how do I go submitting that as a bug?

Link to comment
Share on other sites

  • WHMCS Staff

Hi @bendrop,

I did some testing in WHMCS v7.7.1 and confirmed that relid is returned as expected:

Array ( [messagename] => Support Ticket Opened by Admin [relid] => 2 )

If you do believe however that you've found a bug (Perhaps you're replicating it a different way than I did), then we welcome reports at https://www.whmcs.com/bugs/

Link to comment
Share on other sites

7 hours ago, WHMCS Peter said:

Hi @bendrop,

I did some testing in WHMCS v7.7.1 and confirmed that relid is returned as expected:


Array ( [messagename] => Support Ticket Opened by Admin [relid] => 2 )

If you do believe however that you've found a bug (Perhaps you're replicating it a different way than I did), then we welcome reports at https://www.whmcs.com/bugs/

Hi Peter.

Ah, that's not the right template/message name.

The one sent to the admin/staff when a new ticket is opened/updated is "Support Ticket Change Notification"

Link to comment
Share on other sites

  • WHMCS Staff

Hi @bendrop,

Oops! That is certainly why I couldn't reproduce it! Thanks for submitting your report.

I can see that this issue was confirmed by our team and as such, internal case #CORE-13261 has been opened to rectify this in future releases.

Do keep an eye on our Change Log (http://changelog.whmcs.com/) for this case ID.

Thanks again!

Link to comment
Share on other sites

  • 2 months later...

Hi @WHMCS Peter,

Are there any plans to add support (ticket) custom fields into WHMCS as accessible variables (similar to client and service custom fields) so that others don't need to write php to use them in email templates?

I'd also like to use my support (ticket) custom fields in email templates, however really not confident as a non-developer user in using the above method... Unless you'd like to post all the code and step by step instructions? 🙂

 

Link to comment
Share on other sites

15 hours ago, Rusky said:

Hi @WHMCS Peter,

Are there any plans to add support (ticket) custom fields into WHMCS as accessible variables (similar to client and service custom fields) so that others don't need to write php to use them in email templates?

I'd also like to use my support (ticket) custom fields in email templates, however really not confident as a non-developer user in using the above method... Unless you'd like to post all the code and step by step instructions? 🙂

 

Don't worry Rusky! When they fix the above mentioned bug, I'll post the code I have to allow you to insert the variables yourself 🙂

Link to comment
Share on other sites

  • 6 months later...

@WHMCS Peter

So I installed the update today - the $vars are now in there, BUT, the custom fields aren't written to the database until AFTER the emailpresend hook is fired :(

So there is no way to get them directly from the database with a nice call, it seems we can only do it using the $_POST data which is pretty messy.

Link to comment
Share on other sites

Anyway, here is the hook file you need - it's using the $_POST data for now, which works, I just prefer a single DB call.

I've left the code for both methods in (commented out) so in the future, if this is "fixed" then you can switch it.

Put the file in your /includes/hook folder then update the "Support Ticket Change Notification" email :

Under:

Priority: {$ticket_priority}

Add:

{if $customfields}{foreach $customfields as $customfield}
{$customfield.name}: {$customfield.value}{/foreach}{/if}

 

customfieldsinticket.php

Link to comment
Share on other sites

2 hours ago, bendrop said:

Anyway, here is the hook file you need - it's using the $_POST data for now, which works, I just prefer a single DB call.

I've left the code for both methods in (commented out) so in the future, if this is "fixed" then you can switch it.

Put the file in your /includes/hook folder then update the "Support Ticket Change Notification" email :

Under:


Priority: {$ticket_priority}

Add:


{if $customfields}{foreach $customfields as $customfield}
{$customfield.name}: {$customfield.value}{/foreach}{/if}

 

customfieldsinticket.php

Thank you for sharing this, it should help a lot.

Link to comment
Share on other sites

3 hours ago, bendrop said:

Anyway, here is the hook file you need - it's using the $_POST data for now, which works, I just prefer a single DB call.

I've left the code for both methods in (commented out) so in the future, if this is "fixed" then you can switch it.

Put the file in your /includes/hook folder then update the "Support Ticket Change Notification" email :

Under:


Priority: {$ticket_priority}

Add:


{if $customfields}{foreach $customfields as $customfield}
{$customfield.name}: {$customfield.value}{/foreach}{/if}

 

customfieldsinticket.php

I added this in, and it works.

I was wondering however, would it be possible to separate each filed onto a new line?  

Link to comment
Share on other sites

46 minutes ago, bendrop said:

It should already do that - make sure you add the carriage return after "{foreach $customfields as $customfield}"

It's not a display issue, that should be 2 lines of added code there 🙂

I did not have the carriage return, I copied and pasted, and the carriage return did not carry over, I have added it now.

Thank you!

Off the subject, do you happen to know how to add information about the clients selected service to this email as well?

Edited by shadvalentine
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated