set date to customfield via groovy during creating transition

Hi.

I'm trying to set the current date to our customfield deadline in the creattion transition.
This doesn't work...

Here is my groovy script:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import org.apache.log4j.Category
import java.sql.Timestamp
log = Category.getInstance("com.oncreate.jira.groovy.Deadline")
log.setLevel(org.apache.log4j.Level.DEBUG)
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder()
Issue issue  = issue
def date1 = new Timestamp(new Date().getTime())
if ( issue.projectObject.name == 'Tagesgeschäft WP' )
{
  def cfDeadline = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Deadline'}
  if ( !issue.getCustomFieldValue(cfDeadline) ) {
     log.debug "Deadline not set for "+issue.getKey() + "  " + date1.toString()
     cfDeadline.updateValue(null, issue, new ModifiedValue("", date1), changeHolder)
     log.debug "Deadline now set to: " +issue.getCustomFieldValue(cfDeadline)
  } else {
     log.debug "Deadline is already set for "+issue.getKey()+": "+issue.getCustomFieldValue(cfDeadline)
  }
}
else {
  log.debug "Nothing to do. Project != Tagesgeschäft WP"
}

 

and the lines from the log file:

2014-12-09 12:39:31,792 QuartzScheduler_Worker-0 DEBUG ServiceRunner    DBT [oncreate.jira.groovy.Deadline] Deadline not set for null  2014-12-09 12:39:31.781
2014-12-09 12:39:31,883 QuartzScheduler_Worker-0 DEBUG ServiceRunner    DBT [oncreate.jira.groovy.Deadline] Deadline now set to: null
2014-12-09 12:39:32,201 QuartzScheduler_Worker-0 INFO ServiceRunner    DBT [atlassian.mail.incoming.mailfetcherservice] DBT[10111]: Issue DBT-8172 created

 

What can I do to set the customfield as postfunction of creation transition?

 

Thanks in advance.

Petra

 

2 answers

This widget could not be displayed.

Have you checked the order or the post functions? Issue must probably be created before using the "issue" variable in the script. Call script after "Create Issue originally"

This widget could not be displayed.

Thanks for your help.
It works very good now.

I have one more question.
What do I have to do, to remove the time from my timestamp. --> Set it to 00:00 ???

 

Thanks a lot.

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 New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

155 views 2 0
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