[SOLVED] Javascript execution in OTRS6 AgentTicketEmail

Moderator: crythias

Post Reply
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

[SOLVED] Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

Hey there, I can't seem to execute javascript code (even simple alert boxes) if I put javascript in the AgentTicketEmail template.

Simple Example, not even speaking of element manipulation ($('element').hide()):

Code: Select all

<script type="text/javascript">
alert('test');
</script>
My questions are:
What am I missing, why isn't the code executed?
Is OTRS using jquery or its own version of it/something else?

Thanks in advance!
Last edited by tomp on 12 Sep 2018, 14:19, edited 1 time in total.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by jojo »

security. For sure you can not put active content in a template
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

Is there a way to disable this security option or implement javascript another way?
I would like to display Dynamic Fields depending on the Template chosen.
jojo
Znuny guru
Posts: 15019
Joined: 26 Jan 2007, 14:50
Znuny Version: Git Master
Contact:

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by jojo »

There is a module called Dynamic Ticket Templates available for our customers. Or you can use the Process Management module to create differrent forms...
"Production": OTRS™ 8, OTRS™ 7, STORM powered by OTRS
"Testing": ((OTRS Community Edition)) and git Master

Never change Defaults.pm! :: Blog
Professional Services:: http://www.otrs.com :: enjoy@otrs.com
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by zzz »

Hello,

try to escape your code with:

Code: Select all

<script type="text/javascript">//<![CDATA[
'use strict';
alert('test');
//]]></script>
If the code doesn't appear in your browsers source code, it's probably a caching issue (browser or OTRS).
OTRS removed JavaScript from the Template Toolkit (.tt)—v5->v6—to separate templates and logic.
You should follow that paradigm and create your own JavaScript files and register them in a XML file.

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

Free and premium add-ons: German | English
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

Thanks, that is very helpful information!

I already tried the escaping without effect but separating the javascript makes sense.
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

I'm still having trouble implementing javascript.

/opt/otrs/var/httpd/htdocs/js/thirdparty/Customization/test.js:

Code: Select all

$( document ).ready(function() {
    alert( "ready!" );
});
/opt/otrs/Kernel/Config/Files/Customization.xml:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<otrs_config version="1.0" init="Framework">
<ConfigItem Name="Loader::Agent::CommonJS###110-Customization" Required="1" Valid="1">
    <Description Translatable="1">List of JS files for package "Customization".</Description>
    <Group>Framework</Group>
    <SubGroup>Core::Web</SubGroup>
    <Navigation>Frontend::Base::Loader</Navigation>
    <Setting>
        <Array>
            <Item>thirdparty/Customization/test.js</Item>
        </Array>
    </Setting>
</ConfigItem>
<ConfigItem Name="Loader::Customer::CommonJS###110-Customization" Required="1" Valid="1">
    <Description Translatable="1">List of JS files for package "Customization".</Description>
    <Group>Framework</Group>
    <SubGroup>Core::Web</SubGroup>
    <Navigation>Frontend::Base::Loader</Navigation>
    <Setting>
        <Array>
            <Item>thirdparty/Customization/test.js</Item>
        </Array>
    </Setting>
</ConfigItem>
</otrs_config>
This is just an example but the javascript file isn't embedded into OTRS, so isn't the alert box.
I restarted the webserver and otrs.Daemon.pl, plus ran otrs.setPermissions.pl.

Are there any additional steps I'm missing? Do I have to register the Customization.xml or recreate the cache?
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by zzz »

Are you really on version 3.2?
If so, the config looks correct, however you should change "Framework" to "Application".

Use ./bin/otrs.RebuildConfig.pl and check if your settings appear in the SysConfig.
You should also disable the configuration Loader::Enabled::JS.

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

Free and premium add-ons: German | English
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

Hi Emin, I just updated my profile information, I'm running 6.0.8.

Also I discovered the solution and added the file via Sysconfig in the Loader::Module::AgentTicketEmail###002-Ticket Setting.

I somehow have removed the "New Email-Ticket" Entry in the navigation, any chance you could help me out, how to fix this?
zzz
Znuny superhero
Posts: 888
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by zzz »

The XML format looks a bit different in version 6 but it's absolutly fine if you've added it in the config.

Missing entry: Search for "Frontend::Navigation###AgentTicketEmail###002-Ticket". It should deviate from standard (outlined in grey).
Press on the three horizontal lines and reset that config.

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

Free and premium add-ons: German | English
tomp
Znuny newbie
Posts: 16
Joined: 29 Aug 2018, 11:04
Znuny Version: 6.0.8

Re: Javascript execution in OTRS6 AgentTicketEmail

Post by tomp »

I added a character into a GroupRo Field of a AgentTicketEmail variable by mistake.

Thanks, I'll mark the thread as solved.
Post Reply