JIRA - Set a custom field date six months from now - Scriptrunner addon

Tom October 21, 2019

Hi All,

I'm looking to add a post function to a Jira workflow that sets the date in a custom field to a 1 month from now,

I have now idea idea how to do this, but something that seems quite simplistic in my head, ie. Date = date+30, seems to be unnecessarily complicated in Jira. 

I have the script-runner add-on together with the standard Jira functionality, any ideas where to start?

Your help is greatly appreciated.

Tom

3 answers

0 votes
Tom October 28, 2019

Hi All,

Based on what's been said above I now have the below code:

import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def csDate2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Forecast Date")

Timestamp csDate1Value = (Timestamp) issue.getCreated()
Date csNewDateValue = new Date(csDate1Value.getDate());
csDate2.updateValue(null, issue, new ModifiedValue("", (Object) csNewDateValue), new DefaultIssueChangeHolder())

 

This is not working and am getting the error "org.ofbiz.core.entity.GenericTransactionException: Commit failed, rollback previously requested by nested transaction."

I'm also not sure where the one month or 6 month, etc time period is defined above, this doesn't appear to make a lot of sense based on what i'm reading.

Please can anyone advise?

I don't understand why this is so hard.

0 votes
Kevin Johnson
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 21, 2019

1.create a custom field for user to set the desired date 

2.create a script that reads the current date and create a function to add 6 months from the current date that is given by the user 

3.try printing the changed date data to the variable and to another custom field or to the same custom filed 

hope this help 

try the script runners documentation for the this process i would suggest you to use behaviours from the scriptrunner 

https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html 

0 votes
Sreenivasaraju P
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.
October 21, 2019

Hi,

PLease refer below link. It is similar question. It may help you.

https://community.atlassian.com/t5/Jira-questions/Set-date-on-a-custom-field-using-script-runner/qaq-p/772994

 

def csDate2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved On")

Timestamp csDate1Value = (Timestamp) issue.getCreated()
Date csNewDateValue = new Date(csDate1Value.getTime() + 30*24*60*60*1000);
csDate2.updateValue(null, issue, new ModifiedValue("", (Object) csNewDateValue), new DefaultIssueChangeHolder())
Tom October 25, 2019

Hi,

So i have the below.

 

import java.sql.Timestamp
import com.atlassian.jira.issue.ModifiedValue

def csDate2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Forecast Date")

Timestamp csDate1Value = (Timestamp) issue.getCreated()
Date csNewDateValue = new Date(csDate1Value.getTime() + 30*24*60*60*1000);
csDate2.updateValue(null, issue, new ModifiedValue("", (Object) csNewDateValue), new DefaultIssueChangeHolder())

 

Getting the error: Unable to resolve class DefaultIssueChangeHolder

Any ideas?

Suggest an answer

Log in or Sign up to answer