Scriptrunner escalation service set date field

Hi

I'm struggling to find a syntax that will update a custom date field using scriptrunner escalation service

my code is 

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.id == 'customfield_13202'}
Date curr = new Date()
Calendar cal = Calendar.getInstance()
cal.setTime(curr)
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
String dateFormat = "d/MMM/yy"
try {
issueInputParameters.addCustomFieldValue(cf.id, new java.text.SimpleDateFormat(dateFormat).format(cal.getTime()))
} catch (Exception e) {
log.debug(e.getMessage())
}

The date format is accepted by date field in edit. I can set fields like description, Field id is correct

debugging doesn't highlight an issue

log.debug("cal 1 " + cal.getTime())
log.debug("cal 2 " + new java.text.SimpleDateFormat(dateFormat).format(cal.getTime()))
log.debug("field " + cf.id +"/"+ cf.getIdAsLong())

->

[c.onresolve.jira.groovy] 
[c.onresolve.jira.groovy] cal 1 Mon Feb 20 11:47:36 GMT 2017
[c.onresolve.jira.groovy] cal 2 20/Feb/17
[c.onresolve.jira.groovy] field customfield_13202/13202
[c.onresolve.jira.groovy] [20/Feb/17]

has anyone got this to work. I've seen some similar posts but no conclusive approach

Tom

2 answers

1 accepted

I have a solution

Putting the field onto the edit screen allowed it to be updated

my code was

issueInputParameters.skipScreenCheck()

which I thought bypassed the need to put the field on a screen.

Should have been

issueInputParameters.setSkipScreenCheck(true)

 

Yes - the first format just returns whether skip screen check is set. 

0 votes
Tarun Sapra Community Champion Feb 20, 2017

Hello Tom,

Can you try this format for dateFormat

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")

This should give the same o/p while debugging - 20/Feb/17 and should do the trick

 
none of the formats I've tried are updating the customf field
dd/MM/yyyy has debug

[c.onresolve.jira.groovy] cal 1 Mon Feb 20 14:21:11 GMT 2017
[c.onresolve.jira.groovy] cal 2 20/02/2017
[c.onresolve.jira.groovy] field customfield_13202/13202
[c.onresolve.jira.groovy] [20/02/2017]

dd/MMM/yyy has debug

[c.onresolve.jira.groovy] cal 1 Mon Feb 20 14:26:40 GMT 2017
[c.onresolve.jira.groovy] cal 2 20/Feb/2017
[c.onresolve.jira.groovy] field customfield_13202/13202
[c.onresolve.jira.groovy] [20/Feb/2017]

if i put a bad date in the edit field i will get the message

"You did not enter a valid date. Please enter the date in the format "d/MMM/yy", eg. "20/Feb/17"

and the debug for that format is

[c.onresolve.jira.groovy] cal 1 Mon Feb 20 14:35:52 GMT 2017
[c.onresolve.jira.groovy] cal 2 20/Feb/17
[c.onresolve.jira.groovy] field customfield_13202/13202
[c.onresolve.jira.groovy] [20/Feb/17]

I think there is an error somewhere that is not reported. I'll see if I can turn some JIRA logging onto DEBUG for more info

Tarun Sapra Community Champion Feb 20, 2017

Just a hunch,

in the method "addCustomFieldValue"  instead of cf.id did you try, cf.getIdAsLong() , as your method expects "fullCustomFieldKey" -->> addCustomFieldValue(String fullCustomFieldKey, String... values)

 and I am not sure if cf.id returns full custom field key. thus better to use the method

 

addCustomFieldValue(Long customFieldId, String... values)

yes i've tried getId, getName, getIdAsLong

debug line [c.onresolve.jira.groovy] field customfield_13202/13202 

is from log.debug("field " + cf.id +"/"+ cf.getIdAsLong())

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

409 views 1 13
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot