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, team ’25 europe, early bird extension, conference discount, barcelona, hybrid event, AI teamwork, early bird pass, digital access, collaboration conference, atlassian events, register now, developer conference

1 week left to save on your Team '25 Europe pass

Still thinking about joining us for Team '25 Europe? Early bird has been extended for just one week! Now’s the time to lock in your lowest rate. Use code TEU25COMM-20 to save 20% at checkout. Hurry, this only lasts for 1 more week.

Learn more
AUG Leaders

Atlassian Community Events