• 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

This widget could not be displayed.

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
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 yesterday 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...

78 views 1 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