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

This widget could not be displayed.
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.

This widget could not be displayed.

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.

This widget could not be displayed.

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
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

295 views 1 4
Join discussion

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