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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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) |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jumping into an old thread in case it helps someone in the future. The way I was ultimately able to work around this was by ending my code with:
def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
log.info(update.getErrorCollection().toString())
if (update.isValid()) {
issueService.update(user, update)
}
this returned
INFO : Errors: {customfield_27220=Invalid date format. Please enter the date in the format "dd/MMM/yy h:mm a".} Error Messages: []
So I knew I needed to use SimpleDateFormat("dd/MMM/yy h:mm a") for my date. Hope this helps someone!
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.