Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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())

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?

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 

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,308 views 22 31
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you