[SOLVED] Add pre-defined value for To, Cc, Bcc field

Moderator: crythias

Post Reply
tpsupport
Znuny newbie
Posts: 75
Joined: 02 Feb 2011, 14:45
Znuny Version: 6.0.12

[SOLVED] Add pre-defined value for To, Cc, Bcc field

Post by tpsupport »

Hi,

My current challange is to pre-define an email address in the Bcc field when replying, forwarding or opening a new ticket in OTRS 6. There is already a post explaining how to use AdminTemplate to set a specific State depending on the Template which is used, see https://forums.otterhub.org/viewtopic.p ... 18#p159518. This requires e.g. editing AgentTicketCompose.pm.
It would be great if I could just speficy an email address for the Bcc field and have it instered when a specific template is used. I was not able to reuse the above linked approach for Bcc.
Another variant is to use just a button defining a template within the template files (e.g. AgentTicketEmail.tt), see http://lists.otrs.org/pipermail/otrs/20 ... 42612.html. This works but first needs another click on a button to fill the form and second does not seems to work for AgentTicketCompose.

I really just need to add a pre-edfined email address in the Bcc field. If not possible otherweise then I am even ok if the Bcc field is always prefilled in all forms and not on only demand.

Thanks for your help!
Last edited by tpsupport on 12 Jun 2018, 09:44, edited 1 time in total.
Znuny 6.5 LTS - Ubuntu 20.04 x64, Azure Database for MySQL server 5.7, Perl 5.22.1, Apache/2.4.18
tpsupport
Znuny newbie
Posts: 75
Joined: 02 Feb 2011, 14:45
Znuny Version: 6.0.12

Re: Add pre-defined value for To, Cc, Bcc field

Post by tpsupport »

I found a very intersting post that might solve my issue but the solution does not seem to fit for OTRS 6 because javascript has been removed from templates, see https://blog.otrs.com/2017/03/21/no-jav ... -tt-files/.

Kludge to assign a State to a Response Template
https://forums.otterhub.org/viewtopic.php?f=60&t=38844

The link would be e.g.:

Code: Select all

otrs/index.pl?Action=AgentTicketEmail&Subaction=StoreNew&ExpandCustomerName=2&CustomerTicketCounterBccCustomer=1&BccCustomerTicketText_1=mail@domain.com
This works when calling it manually. Now I just need to find the right file to add it permanently. Any thoughts?
Znuny 6.5 LTS - Ubuntu 20.04 x64, Azure Database for MySQL server 5.7, Perl 5.22.1, Apache/2.4.18
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Add pre-defined value for To, Cc, Bcc field

Post by zzz »

Hello,

a simple predefined BCC field can be inserted with this code:

Code: Select all

$(document).ready(function() {
    setTimeout(function() {
        const Action = Core.Config.Get('Action');
        const SupportedActions = ['ActionTicketPhone', 'AgentTicketEmail', 'AgentTicketForward', 'AgentTicketCompose'];
        if ($.inArray(Action, SupportedActions) !== -1) $('#BccCustomer').val('yourmail@yourmail.com').trigger('change');
    }, 0);
});
Save it in '/opt/otrs/var/httpd/htdocs/js/FillBcc.js' and add 'FillBcc' to the SystemConfiguration 'Loader::Agent::CommonJS###000-Framework'.

You can extend the functionality with your own if statements. Changes will be lost on update if not packaged.

Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
tpsupport
Znuny newbie
Posts: 75
Joined: 02 Feb 2011, 14:45
Znuny Version: 6.0.12

Re: Add pre-defined value for To, Cc, Bcc field

Post by tpsupport »

Hi Emin,

Thank you for your reply! This works just as you wrote, and I would like to add the additional "if" statement for "ResponseID", what do I need to specify?

I expect it to be something like this:

Code: Select all

if ($.inArray(Action, SupportedActions) !== -1 && $Param(ResponseID) == 1)
Thanks for looking at it!
Znuny 6.5 LTS - Ubuntu 20.04 x64, Azure Database for MySQL server 5.7, Perl 5.22.1, Apache/2.4.18
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Add pre-defined value for To, Cc, Bcc field

Post by zzz »

the logic is correct but the second part is Perl. It should look like this instead:

Code: Select all

$(document).ready(function() {
    setTimeout(function() {
        const Action = Core.Config.Get('Action');
        const SupportedActions = ['ActionTicketPhone', 'AgentTicketEmail', 'AgentTicketForward', 'AgentTicketCompose'];
        if ($.inArray(Action, SupportedActions) !== -1) {
            if (Action === 'AgentTicketCompose') {
                const ResponseID = $('input[name=ResponseID]').val();
                if (ResponseID == 1) FillBcc('email1@testmail.test');
                else if (ResponseID == 2) FillBcc('email2@testmail.test');
                else FillBcc('defaultcompose@testmail.test')
            }
            else FillBcc('defaultmail@testmail.test')
        }

        function FillBcc(email) {
            $('#BccCustomer').val(email).trigger('change');
        }
    }, 0);
});
Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
tpsupport
Znuny newbie
Posts: 75
Joined: 02 Feb 2011, 14:45
Znuny Version: 6.0.12

Re: Add pre-defined value for To, Cc, Bcc field

Post by tpsupport »

Thanks Emin! This works great for the Reply function. I think rather than using ResponseID it would be better in my case to use QueueID for the if statement since only tickets in specific queues should get the BCC address. When forwarding an article the queue is already given, so I guess I would just have to defince another 'const' that gets the queue value?
In case of EMail or Phone Ticket creation I would make it dependent on the queue thas is chosen by the Agent in order to have it filled automatically. So, I guess I have to do it via a different function, maybe "$('#QueueID').on('change', function ()" ?

Could you please give me at least that hint how to fill the QueueID const? I have tried "const QueueID = $('input[name=QueueID]').val();" without success.
Again, thank you very much!
Znuny 6.5 LTS - Ubuntu 20.04 x64, Azure Database for MySQL server 5.7, Perl 5.22.1, Apache/2.4.18
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Add pre-defined value for To, Cc, Bcc field

Post by zzz »

tpsupport wrote: 08 Jun 2018, 16:26 Thanks Emin! This works great for the Reply function. I think rather than using ResponseID it would be better in my case to use QueueID for the if statement since only tickets in specific queues should get the BCC address. When forwarding an article the queue is already given, so I guess I would just have to defince another 'const' that gets the queue value?
Unfortunately, the form doesn't provide information about the queue. You'd have to change the URL of the forward link in AgentTicketZoom (just like crythias did) or change the Perl code.
tpsupport wrote: 08 Jun 2018, 16:26 In case of EMail or Phone Ticket creation I would make it dependent on the queue thas is chosen by the Agent in order to have it filled automatically. So, I guess I have to do it via a different function, maybe "$('#QueueID').on('change', function ()" ?
Yes, exactly. Some help:

Code: Select all

$('#Dest').change(function() {
    let Queue = $(this).val().split('||')[1];
    // Do stuff with Queue
    // console.log(Queue)
});
Best regards
Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
tpsupport
Znuny newbie
Posts: 75
Joined: 02 Feb 2011, 14:45
Znuny Version: 6.0.12

Re: Add pre-defined value for To, Cc, Bcc field

Post by tpsupport »

Thanks again Emin. Now I have a working solution for Response Templates and AgentTicketEmail. For Forwards I will adjust the URL.

FillBcc.js

Code: Select all

// This is for Ticket Responses
// We can use the ResponseID
$(document).ready(function() {
    setTimeout(function() {
        const Action = Core.Config.Get('Action');
        const ResponseID = $('input[name=ResponseID]').val();
	const SupportedActions = ['ActionTicketPhone', 'AgentTicketEmail', 'AgentTicketForward', 'AgentTicketCompose'];
        if ($.inArray(Action, SupportedActions) !== -1  && ResponseID == 2) $('#BccCustomer').val('forward@bcc.mail').trigger('change');
    }, 0);
});

// This is for AgentTicketEmail
// We can use the QueueID
$('#Dest').change(function() {
    let Queue = $(this).val().split('||')[1];
	if (Queue == 'ThisQueue') $('#BccCustomer').val('forward@bcc.mail').trigger('change');
});

// For AgentTicketForward there is no ResponseID or Queue thus the URL has to be adjusted
Znuny 6.5 LTS - Ubuntu 20.04 x64, Azure Database for MySQL server 5.7, Perl 5.22.1, Apache/2.4.18
Post Reply