• 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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

281 views 4 9
Read article

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