• Community
  • Products
  • Jira
  • Questions
  • I want a custom field which should hold the value 2 days ahead of version release date i.e if the version release date is 2014-01-02 the custom field should have the value automatically 2014-01-04 . Please help me how to do this .

I want a custom field which should hold the value 2 days ahead of version release date i.e if the version release date is 2014-01-02 the custom field should have the value automatically 2014-01-04 . Please help me how to do this .

I want a custom field which should hold the value 2 days ahead of due date i.e if the due date is 2014-01-02 the custom field should have the value automatically 2014-01-04 . Please help me how to do this .

1 answer

1 vote

Easiest way to do this is to use the script-runner add-on to provide a "scripted field".

Or you'll have to write a small plugin to provide a field that does this.

I solved the issue by using IssueEvent api .

@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
Long eventTypeId = issueEvent.getEventTypeId();
Issue issue = issueEvent.getIssue();
System.out.println("Issue object is : "+issue);
Collection<Version> versionCollection = issue.getFixVersions();
Date date = null ;
for(Version version : versionCollection){
date = version.getReleaseDate();
break;
}
System.out.println("Issue Realease date is : "+date);
// if it's an event we're interested in, log it
if (eventTypeId.equals(EventType.ISSUE_CREATED_ID)) {
log.info("Issue {} has been created at {}.", issue.getKey(), issue.getCreated());
System.out.println("Issue is created , issue key is :"+issue.getKey());
IssueManager issueManager = com.atlassian.jira.ComponentManager.getInstance().getIssueManager();
System.out.println("issueManager :"+issueManager);
CustomFieldManager cfManager = com.atlassian.jira.ComponentManager.getInstance().getCustomFieldManager();
System.out.println("cfManager :"+cfManager);
MutableIssue missue = issueManager.getIssueObject(issue.getKey());
System.out.println("MutableIssue :"+missue);
CustomField cf = cfManager.getCustomFieldObjectByName("MyMapDate");
System.out.println("CustomField :"+cf);
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
System.out.println("IssueChangeHolder :"+changeHolder);

Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DAY_OF_YEAR, 2);
Date dates = c.getTime();
cf.updateValue(null, missue, new ModifiedValue(missue.getCustomFieldValue(cf), ""+dates),changeHolder);
System.out.println("Updated date is :"+changeHolder.getChangeItems().get(0));
} else if (eventTypeId.equals(EventType.ISSUE_RESOLVED_ID)) {
log.info("Issue {} has been resolved at {}.", issue.getKey(), issue.getResolutionDate());
} else if (eventTypeId.equals(EventType.ISSUE_CLOSED_ID)) {
log.info("Issue {} has been closed at {}.", issue.getKey(), issue.getUpdated());
}
}

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,305 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot