I hvae code which works fine to modify custom field value if it is text. I want to update the datetime custom field. I guess date time formatting is wrong in my code.
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
class SummaryStatusDate extends AbstractIssueEventListener {
Logger log = Logger.getLogger(SummaryStatusDate.class)
@Override
void workflowEvent(IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)
def field = event.getChangeLog().getRelated('ChildChangeItem').any{ it.field.toString().equalsIgnoreCase("Summary Updated")}
if (field){
MutableIssue issue = event.issue
ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Summary Update Date"}
log.debug "Field: " + cf
//def today = new Date()
//log.debug today
//log.debug (new Date().parse("dd MMM YY H:m", new Date()))
//issue.setCustomFieldValue(cfg, "abc")
//issue.store()
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
DateFormat.getInstance().format(now)),changeHolder);
Date d2 = new SimpleDateFormat("yyyy-MM-dd HH:MM").parse("2014-05-14 11:50")
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), d2),changeHolder)
}
}
}
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import org.apache.log4j.Logger
import static org.apache.log4j.Level.DEBUG
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.index.IssueIndexManager
import java.sql.Timestamp
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
class SummaryStatusDate extends AbstractIssueEventListener {
Logger log = Logger.getLogger(SummaryStatusDate.class)
@Override
void workflowEvent(IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)
def field = event.getChangeLog().getRelated('ChildChangeItem').any{ it.field.toString().equalsIgnoreCase("Summary Updated")}
if (field){
MutableIssue issue = event.issue
ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Summary Update Date"}
def date1 = new Timestamp(new Date().getTime())
issue.setCustomFieldValue(cf, date1)
User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store()
}
}
}
Lots posts on this board asking the same question but I found nothing that works. I used to do tons of Java script, but not for years, and I'm just getting started with Groovy scripts and JIRA config. I beat my head against this problem for hours on end.
Here is something that works for me in a WF transition script:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import static java.lang.Math.* import java.sql.Timestamp //Get current issue Issue issue = issue customFieldManager = ComponentManager.getInstance().getCustomFieldManager() //Getting custom field value cfSSDate = issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Date of Site Survey") ) //Getting custom field object cfoSID = customFieldManager.getCustomFieldObjectByName("Scheduled Install Date") //change Scheduled Install Date to Date of Site Survey + 7 days (604800000ms) dSID = new java.sql.Timestamp(cfSSDate.getTime() + 604800000) //pass setCustomFieldValue a custom field object and a java.sql.Timestamp issue.setCustomFieldValue(cfoSID, dSID) //this works too today = new java.sql.Timestamp(new Date(2015,5,17).getTime()) //issue.setCustomFieldValue(cfoSID, today)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there! I'm trying to use this script to set a timestamp in a custom field (Time Stamp In Progress) in a post-function transition. I need to set Time Stamp In Progress to the current date and time when the transition from Open to In Progress occurs. I'm getting multiple errors:
On line 10: [Static type checking] - cannot find matching method com.atlassian.jira.ComponentManager#getCustomerFieldManager(). Please check if the declared type is correct and if the method exists.
On line 13: [Static type checking] - the variable [cfSSDate] is undeclared.
On line 16: [Static type checking] - the variable [cfoSID] is undeclared.
On line 19: [Static type checking] - the variable [date] is undeclared. Cannot find matching method com.atlassian.jira.issue.MutableIssue#setCustomFieldValue(java.lang.Object). Please check if the declared type is correct and if the method exists.
I don't have much experience with Groovy Scripts, so any advice is appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Lauren Robinette yes I can see this is deprecated https://docs.atlassian.com/software/jira/docs/api/7.11.0/com/atlassian/jira/ComponentManager.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your date format looks wrong, you have MM twice. I think you want a java.sql.Timestamp, not a Date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you please provide me an example
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.
Thanks!
I was able to set time using
issue.setCustomFieldValue(cf,
new
Timestamp(
new
Date(
2012
,
9
,
17
).getTime()))
however how do i set it to current date and time. I counld not find function to pass that to above new Timestamp method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
new Timestamp(new Date()) or something.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i tried couple of options but those did not work :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
date.toTimestamp()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), new java.util.Date()),changeHolder);
but did not work
it throws
org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:CustomFieldValue][id,10270][datevalue,Wed May 14 12:16:21 CDT 2014][issue,10119][parentkey,null][customfield,10009] (Java type java.util.Date not currently supported. Sorry.)
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.