bendrop Posted March 10, 2019 Share Posted March 10, 2019 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 😭 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted March 10, 2019 WHMCS Staff Share Posted March 10, 2019 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 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted March 11, 2019 Author Share Posted March 11, 2019 Hi Peter, Thank you - so I presume in the case of a ticket alert email $vars['relid'] would be the ticket id? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted March 11, 2019 WHMCS Staff Share Posted March 11, 2019 As long as it's a ticket notification, yes. The relid value would be the tbltickets.id value. Correct. 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted March 11, 2019 Author Share Posted March 11, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted March 11, 2019 WHMCS Staff Share Posted March 11, 2019 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/ 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted March 12, 2019 Author Share Posted March 12, 2019 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" 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted March 12, 2019 Author Share Posted March 12, 2019 Bug submitted with code example 🙂 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Staff WHMCS Peter Posted March 12, 2019 WHMCS Staff Share Posted March 12, 2019 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! 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted March 12, 2019 Author Share Posted March 12, 2019 Hopefully it will release soon! cheers! 1 Quote Link to comment Share on other sites More sharing options...
Rusky Posted June 2, 2019 Share Posted June 2, 2019 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? 🙂 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted June 3, 2019 Author Share Posted June 3, 2019 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 🙂 1 Quote Link to comment Share on other sites More sharing options...
shadvalentine Posted December 7, 2019 Share Posted December 7, 2019 On 6/2/2019 at 7:38 PM, bendrop said: 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 🙂 I was wondering if you were able to get this working? 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted December 7, 2019 Author Share Posted December 7, 2019 I'd forgotten all about this, just checking the changelogs it was fixed in 7.8. Not sure if my license is still upgradable, but if it is, ill get that done and post when confirmed it works 😁 1 Quote Link to comment Share on other sites More sharing options...
bendrop Posted December 9, 2019 Author Share Posted December 9, 2019 @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. 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted December 10, 2019 Author Share Posted December 10, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
shadvalentine Posted December 10, 2019 Share Posted December 10, 2019 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. 0 Quote Link to comment Share on other sites More sharing options...
shadvalentine Posted December 10, 2019 Share Posted December 10, 2019 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? 0 Quote Link to comment Share on other sites More sharing options...
bendrop Posted December 10, 2019 Author Share Posted December 10, 2019 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 🙂 1 Quote Link to comment Share on other sites More sharing options...
shadvalentine Posted December 10, 2019 Share Posted December 10, 2019 (edited) 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 December 10, 2019 by shadvalentine 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.