In scriptrunner console i am trying to parse date from String. The server outputs me: Wed Apr 05 16:41:00 EEST 2017
Purpose: Put sysdate value to custom date time field using scriptrunner post functcion.
I need: 2017/04/05 16:41 or 2017.04.05 16:41
import org.apache.log4j.Category;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
def cal1 = Calendar.getInstance();
String format = "yyyy/MM/dd HH:mm";
SimpleDateFormat sdfSource = new SimpleDateFormat(format);
String formatedDate = sdfSource.format(cal1.getTime());
formatedDate
//new Date().parse("yyyy/M/d HH:mm", formatedDate)
Date settings:
Hello,
Many thanks to your answer. It worked. I modified the code a little.
import com.atlassian.jira.issue.Issue import org.apache.log4j.Logger import org.apache.log4j.Level import com.atlassian.jira.component.ComponentAccessor import groovy.time.* import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue import org.apache.log4j.Category; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.sql.Timestamp import com.atlassian.jira.issue.MutableIssue def log = Logger.getLogger("zyglev") log.setLevel(Level.DEBUG) MutableIssue issue = issue def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Start date"} def customFieldValue = issue.getCustomFieldValue(customField) if (customFieldValue) { return 0 } else { def todaysDateTime = new Timestamp((new Date()).time) issue.setCustomFieldValue(customField, todaysDateTime) }
Žygimantas
You can do this with the following code in a custom scripted post-function:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import java.sql.Timestamp MutableIssue issue = issue def customFieldManager = ComponentAccessor.getCustomFieldManager() // replace with your custom field id def customFieldId = "customfield_10028" def customField = customFieldManager.getCustomFieldObject(customFieldId) def todaysDateTime = new Timestamp((new Date()).time) issue.setCustomFieldValue(customField, todaysDateTime)
You will need to change the custom field id above to match your date time field. The post-function also needs to be in the list before the change history one. This is explained in more detail here.
Let us know how you get on with this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.