My scripted fields render wrong, with strange symbols

I have some groovy files inside a JIRA plugin developed by our team. I install that plugin into JIRA and make scripted fields pointing to that groovy files, using the ScriptRunner plugin. Everythink works fine except for the fields rendering. If I view those fields on a view issue screen, and I refresh it with F5, sometimes the fields render wrong, being Spanish characters as ñ, á, é, í, ó, ú, rendered as question marks. I know that it is a character encoding problem.

The only thing I don't understand is that ON SUCCESSIVE SCREEN REFRESHINGS WITH F5 SOMETIMES THE FIELDS RENDER WELL AND SOMETIMES WRONG. Why the hell is this happeing? Really the browser must be kidding me. Does the character encoding change in successive screen refreshes? What kind of joke is this? Shouldn't the same character encoding be used always? Really I think it has no sense at all that the character encoding changes by pushing F5. I see it as a nasty joke. What do you think?

3 answers

1 accepted

0 vote
Mahesh S Community Champion Jun 08, 2016

Please add this piece of code on the top of your script (below the import section) and try. It might be a browser cache issue.

enableCache = {-> false}

Thank you. I will try it. Nevertheless, when I was testing the scripted fields, I am very sure that the browser cache was disabled. I always do that, it is an habit of mine.

Mahesh S Community Champion Jun 08, 2016

True! But there will be cache from the server end as well.

No it doesn't work. I am experiencing the same issue. In addition, when I am on the scripted fields management section there is a preview button to see how would the field render for a certain JIRA issue, and it always shows well. It is a problem that only shows on the view issue screen.

Really I can't understand anything. This has no sense. At all. No sense. What a hell.

Mahesh S Community Champion Jun 08, 2016

A few questions please.

  • Does this happens for all your scripted fields?
  • What is the type of output (like html,..) of your scripted field?
  • Can you please share the skeleton of your code with dummy values?

It happens for all scripted fields.

They are of type text.

The code of an scripted field:

import java.text.DateFormat
import java.text.SimpleDateFormat
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
def dateFormat = new SimpleDateFormat("dd/MM/yyyy") as DateFormat
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def closeCustomField = customFieldManager.getCustomFieldObjectByName("Fecha y hora de cierre")
def closeValue
if (closeCustomField == null) {
closeValue = null;
}
else {
closeValue = issue.getCustomFieldValue(closeCustomField) as Date
}
if (closeValue) {
dateFormat.format(closeValue)
}
else {
"no ha sido cerrada aún"
}

Nearly at the bottom, when it says a phrase in Spanish with the character ú, is where the problem happens.

Also I have a cache problem as you said, because I am trying to make changes on the fields and I am unable to get those changes reflected on the view Issue screen although I disabled cache on the groovy files by putting your code below the imports.

Mahesh S Community Champion Jun 08, 2016

Are trying to set the value "no ha sido cerrada aún" to closeValue? I don't understand your last else loop. Please explain what you are trying out.

If the custom field that retains the closing date of the issue has no value, then I return an String for noticing the user.

0 vote

No need to be quite so dramatic about it. UTF8 wasn't invented just to screw over Mikel Rodriguez.

What template is being used for the field, can you attach a screen cap of the script field config?

Can you make a simple script field with the script:

"ñ, á, é, í, ó, ú"

and see how that renders?

 

 

XD XD well at least I had some laughs. You have read my mind. Character encodings have screwed over me since the beginning of times... It is a problem of which I have always been unable to get rid of.

I don't know how to say this but I restarted JIRA and I am utterly unable to reproduce the problem. It never happens now. It seems that simply JIRA gone crazy, which is not a new thing...

Something that really grinds my gears is that when developing for JIRA it is very frequent that I have lots of troubles that later disappear magically with a restart or something like that, in a way that I never know what is the cause, or if I done something wrong.

I don't know how to say this but I restarted JIRA and I am utterly unable to reproduce the problem. It never happens now. It seems that simply JIRA gone crazy, which is not a new thing...

Something that really grinds my gears is that when developing for JIRA it is very frequent that I have lots of troubles that later disappear magically with a restart or something like that, in a way that I never know what is the cause, or if I done something wrong.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 2 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

13 views 0 3
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