Autocompletion today's date in transition (Scriptruner)

Boris Demain June 18, 2019

Hi !

I want to autocomplete a date customfield with the today's date during a screen transition if it's empty.

I wrote this script in a behavior which select field and transition :

def champDateLivre = getFieldById( "customfield_10400" )

def dateDuJour = new Date()

dateDuJour = dateDuJour.format( "d/MMM/yy" )

def valeurInitiale = getFieldById( "customfield_10400" ).value

if ( valeurInitiale == "" )
{ champDateLivre.setFormValue(dateDuJour)
}

I get the date in the customfield BUT when I validate the transition I get error message : "Format de date non valide. Veuillez saisir la date au format 'd/MMM/yy'"
= Invalide date format. Please use format dat 'd/MMM/yy'

 

Is that one iI use and I verified configuration jira.date.picker.java.format : is the same...

Can someone help me ?

Thanks

1 answer

1 accepted

0 votes
Answer accepted
fjodors
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.
June 18, 2019

Hi

Have you tried to enable log and check if your dateDuJour variable has required format?

Something like this:


import org.apache.log4j.Category
...
log.setLevel(org.apache.log4j.Level.INFO)
log.info("start info logging");
log.info(dateDuJour);

Boris Demain June 18, 2019

Thanks for your answer but I don't know how does it work...

Sry I'm not a developper

fjodors
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.
June 18, 2019

Put in your code these rows, then run your postfunction and check log to see result

 

import org.apache.log4j.Category

log.setLevel(org.apache.log4j.Level.INFO)
log.info("start info logging");
log.info(dateDuJour);

Boris Demain June 18, 2019

I tried but it's not a postfunction...

I'm in behavior, in field that I want, in "server-side script"

fjodors
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.
June 19, 2019

Here is a example with logging I have performed. Using similar code you can check all your variables from logs

1. enabke logging for behavior

bh1.png

 

2. Create behavior with server-side script

 

bh2.png

 

 

3. check atlassian-jira.log for entries

bh3.png

Boris Demain June 20, 2019

Hi,

I got logs :

2019-06-20 09:07:31,489 [...] /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] start info logging
2019-06-20 09:07:31,489 [...] /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FieldBehaviours] values of dateDuJour variable is --->20/Jun/19
2019-06-20 09:07:31,489 [...] /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.j.groovy.user.FormField] Error converting string '20/Jun/19' to date using format: d/MMM/yy

It's like the date is good but Jira can't got it like a date...

Suggest an answer

Log in or Sign up to answer