How can I add Javascript to Customer Portal?

We have an instance running JIRA  Server v7.1.8 with JIRA Service Desk 3.1.9.

 I need to include arbitrary javascript on the Customer Portal (globally or per service desk, I dont care which)

I can do this easily enough in JIRA core by using the announcement banner but it seems that the Customer portal banner will not allow it and simply renders the script tag as plain text. 

 

6 answers

This widget could not be displayed.
Gerry Tan Atlassian Team Aug 31, 2016

There is no public API to allow you to do that. The closest you can do is to create a P2 plugin with web-resource module, and set the context to <context>customerportal</context>.

But again this is not a supported public API, and only available in server.

Read more about P2 web-resource plugin module here: https://developer.atlassian.com/jiradev/jira-platform/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/web-resource-plugin-module

Fair enough. Do you know what source file in JIRA handles saving the content for the Service Desk announcement banners?

To be honest with you, I would rather modify the save method to not convert the html to html entities so that the tags placed in the banner are actually rendered as html on the portal, essentially duplicating the functionality of the JIRA Core announcement banner. 

We need our admin to have the ability to change the content when needed. The announcement banner is a perfect solution (aside from this self inflicted handicap).

It doesn't really make sense to us why Atlassian chose to block this feature on the customer side.   

This widget could not be displayed.

Hi Steven, thanks for your time. I have to say that I disagree. The JIRA Core announcement banner renders whatever you put in it exactly as you enter it, nothing special there. When Atlassian designed the Service Desk announcement banner, they made the very intentional decision to to strip out the html tags by calling a method on the input such as StringEscapeUtils.escapeHtml() thereby blocking the administrator's ability to add html tags to the banner.  Atlassian states here their reasoning for that (basically that this was done on purpose because Project Admins can edit the SD Banner and Atlassian considers Project Admins to be less trusted than global admins.). 

While I get that, to a degree, all that would be needed to avoid this, is a checkbox on the Global admin side like "Allow HTML in SD Announcement Banner: Yes / No". This way, the Global Admin can decide if they trust their Project Admins (we do).

While a plugin type solution would work, I would prefer to find where Atlassian calls StringEscapeUtils.escapeHtml() (or similar) on the banner input before saving it to the database and simply remove that line. It really shouldn't be any more complicated than that. This would make the banners function the same way on Service Desk as they do on JIRA Core. 

Don't get me wrong, I didn't ask this just to complain. I was honestly hoping that we had just missed the setting to enable HTML somewhere.


Hi. Did you ever find a solution to this? I would like to put just a few lines of css into the announcement banner on the customer portal. I agree that this feature is needed and should be easily changeable. Thanks

This widget could not be displayed.
Steven Behnke Community Champion Aug 31, 2016

You would need to modify the appropriate templates and files directly. There is no in-UI method to do so.

This widget could not be displayed.

That's sad. Any idea which template/file that would be? Or, better yet, what file can I edit to stop JIRA from rendering the content of the CP banner as plain text? If, I have to modify the source code, that would be a better solution IMHO.

 

This widget could not be displayed.

GGonna report you. Thanks alot

I'm not sure what you mean by this. BTW, "alot" is not a word wink

This widget could not be displayed.
Steven Behnke Community Champion Aug 31, 2016

I think you have this backwards. Atlassian isn't 'blocking' the announcement banner from working. They haven't built in a way to render the HTML tags from the banner. It's likely all escaped and non-functional from the get-go, so a quick 'hack' to prevent or stop that doesn't exist.

This is something that is either considered from the get-go (like core JIRA) or that they build an API for – Neither of those occurred here. Again, they haven't 'blocked' you like you state – They never built that feature like you desire.

I can poke around to find the template used for the portal, but it wouldn't be easy or quick.

The best way would be to take Gerry's method. You could expose an admin screen so someone could add HTML as necessary as well. It is approached as a plugin though.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 13, 2018 in Jira Service Desk

Jira Service Desk – Don’t be afraid, the journey begins with curiosity!

...be more productive while being fun to use at the same time. For some, getting started can be a bit intimidating. This is especially true if Jira Service Desk is your first exposure to Atlassian...

8,850 views 9 28
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you