Community Announcements have moved! To stay up to date, please join the new Community Announcements group today. Learn more
×Hi guys,
it seems for ScriptRunner in the cloud environments, this is already possible.
I did not see any option to get the locale of the user in a script, for example when a listener runs. The Locale.getDefault() method is always returning the default locale of the system, which is not always correct, if I try to update a number field.
Currently, I am trying to update using the default locale and catch the error in case it fails. After that, I am retrying again with the other possible locale.
This works fine, however, I would like to prevent try/catching stuff when checking the locale in advance would allow the correct value from the beginning.
Thanks!
Stefan
Hi,
Did you tried this https://docs.atlassian.com/software/jira/docs/api/7.0.6/com/atlassian/jira/config/LocaleManager.html
it seems that there is a methode that allow you to get the user locale.
thanks for that finding. This is exactly the stuff I needed.
I was able to use this code, which now should be fine for every user language. I had to use formatter.setGroupingUsed(false) as BigDecimal is adding "," for separation of 1000, 1000000 etc. and Jira does not like that:
import com.adaptavist.hapi.jira.issues.Issues
import com.adaptavist.hapi.jira.users.Users
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.LocaleManager
import com.atlassian.jira.issue.Issue
import java.text.NumberFormat
BigDecimal number = 10032.4
def cfID = 16303
LocaleManager localeManager = ComponentAccessor.getComponent(LocaleManager)
Locale userLocale = localeManager.getLocaleFor(Users.getLoggedInUser())
Issues.getByKey("ISSUE-123").update {
NumberFormat formatter = NumberFormat.getInstance(userLocale)
formatter.setGroupingUsed(false)
String formatted = formatter.format(number)
setCustomFieldValue(cfID, formatted)
setEventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH)
setSendEmail(false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.