Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Possibility to get User locale using ScriptRunner in DataCenter?

Stefan Stadler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2025

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

1 answer

1 accepted

0 votes
Answer accepted
Mohamed Benziane
Community Champion
August 25, 2025

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.

Stefan Stadler
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2025

Hi @Mohamed Benziane 

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)

}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
10.3.7
TAGS
AUG Leaders

Atlassian Community Events