Date format in transition (script runner)

Boris Demain July 3, 2019

Hi community,

I try to put due date in date field during transition. I use this script :

// On récupère la valeur dans le champ date Livré Réal
def champDateLivre = getFieldById( "customfield_10400" )

// On crée un objet date
def dateDuJour = new Date();

// On crée la date du jour
dateDuJour = dateDuJour.format( "d/MMM/yy" );

// On récupère la valeur du champ date livré
def valeurInitiale = getFieldById( "customfield_10400" ).value

// Si la date n'est pas alimentée
if ( valeurInitiale == "" )
{

// On l'alimente avec la valeur de date du jour
champDateLivre.setFormValue(dateDuJour)
}

My résult is : 3/Jul/19 but I've got an error that say wrong format. Use d/MMM/yy

But is it.

When I pick the date manualy in calendar, I've got 3/Juil./19

How can I synchronize it ? Exemple force french calendar... or other

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
July 3, 2019

You can get the datepicker format of the current date based on the current user's language using the following:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatterFactory
import com.atlassian.jira.datetime.DateTimeStyle

def formatterFactory = ComponentAccessor.getComponent(DateTimeFormatterFactory.class)
def localDatePicker = formatterFactory.formatter().forLoggedInUser().withStyle(DateTimeStyle.DATE_PICKER)
localDatePicker.format(new Date())
Boris Demain July 4, 2019

Thanks for your answer, but it doesn't work. Does it mean that my user have an other language compare to my systeme ?

PD Sheehan
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.
July 8, 2019

You'll need to provide more details if you want help.

Are you getting errors/stack traces? 

What date string is inputted in your date field?

 

This was just an example of how to get the date in the user's format. Try it in the scriptrunner console. 

To apply to your code, you will need to do something like

champDateLivre.setFormValue(localDatePicker.format(new Date()))
Boris Demain July 8, 2019

I missed the good application.

It's wonderfull, it's work !

Thank you very much Peter-Dave

Suggest an answer

Log in or Sign up to answer