Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • 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 .

Binayak Nanda January 5, 2014

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
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2014

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.

Binayak Nanda January 12, 2014

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
TAGS
AUG Leaders

Atlassian Community Events