Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculated field for date using fixed days

Dav1d J0nes July 16, 2018

I have both JMCF and Scriptrunner so I could go either way with a solution here, I have tried some of the solutions provided in other community articles but no luck getting it to click yet. 

So I have field called "Date of Receipt"

I want to be able to create a due date based on that date + 30 days. So when the user creates the issue they will enter the date of receipt in a custom date field, i want it to display in separate custom field called Issue Due Date the date in the date of receipt field plus 30 days. 

1 answer

1 accepted

0 votes
Answer accepted
Neta Elyakim
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.
July 18, 2018 edited

You can use script runner- add new post function > custom script, and add this code:

import java.sql.Timestamp;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()

def dateCustomField = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(10504 as long))

if(dateCustomField != null){
//if you want to set the system field Due Date
issue.setDueDate( (Timestamp) dateCustomField + 30);

//if you want to set a different custom field of type Date Picker
def customFieldToSet = customFieldManager.getCustomFieldObject(10500 as long)
issue.setCustomFieldValue(customFieldToSet, (Timestamp) dateCustomField + 30);

issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, true)
}
Dav1d J0nes July 18, 2018

This totally worked! Thank you for your help. 

Dav1d J0nes July 18, 2018

One question, can i call the custom field by name instead of ID? 

Neta Elyakim
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.
July 19, 2018

Yes, you can use this-

getCustomFieldObjectByName("field name")

instead of

getCustomFieldObject(10500 as long)

If this work for you please accept the answer :)

Dav1d J0nes July 19, 2018

Done ty again.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, out of office, loom, confluence, async collaboration, meeting recaps, remote teamwork, team alignment, knowledge sharing, AI-powered notes, productivity tools, workforce continuity, teamwork collection

Put your meeting notes on autopilot with Loom + Confluence

AI-powered meeting notes keep work moving even if you’re out of the office. Enjoy your well-deserved time off and return refreshed, confident you’ll catch up in no time.

Learn more
AUG Leaders

Atlassian Community Events