Using Script, How can I manipulate date from customfield ?

Hello,

I write a script using JSS plugin, I get back a date from a customfield and I need to extract data like day, month, year, hour and minute to use my own function and then to update the customfield.

But I have a problem to split the date in day, month, etc.

from com.atlassian.jira import ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import datetime
import time
import myLibrary

customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
customField = customFieldManager.getCustomFieldObject("customfield_10008") #dateEcheance

date = customField.getValue(issue)
day = datetime.datetime.strptime(date, '%d')
month = datetime.datetime.strptime(date, '%m')
year = datetime.datetime.strptime(date, '%Y')
hour = datetime.datetime.strptime(date, '%H')
min = datetime.datetime.strptime(date, '%M')

d = [int(day), int(month), int(year), int(hour), int(min)]

d2, mo2, a2, h2, mi2 = myLibrary.myFunction(d)
issue.setCustomFieldValue(customField, datetime.datetime(a2, mo2, j2, h2, mi2, 0))

2 answers

1 accepted

This widget could not be displayed.

I resolved my problem, the type return is 'java.sql.Timestamp' so I use this doc : [http://docs.oracle.com/javase/6/docs/api/java/util/Date.html]

from com.atlassian.jira import ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
from datetime import datetime
from datetime import date
import java.sql.Timestamp

customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
customField = customFieldManager.getCustomFieldObject("customfield_10008")

dateBlocage = customField.getValue(issue)

y = dateBlocage.getYear() + 1900
mo = dateBlocage.getMonth() + 1
d = dateBlocage.getDate()
h = dateBlocage.getHours()
mi = dateBlocage.getMinutes()

issue.setCustomFieldValue(customField, datetime(y, mo, d, h, mi, 0))

This widget could not be displayed.

I think that the object return by "customField.getValue(issue)" is a java.sql.Timestamp, now I add to find how extract data from a java.sql.Timestamp!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

176 views 18 7
Join discussion

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