Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Get sprint end date and set it to another field scriptrunner

Hello,

We would like to set a value in a date field, based on the sprint end date.

So if the sprint end date is 2/26/2019, that field would get this value.

Would this be possible using scriptrunner? If so, would anyone know how to do that?

Thank you!

2 answers

2 accepted

0 votes
Answer accepted
Nir Haimov Community Leader Feb 28, 2019

Hi @Mihai Mihai 

You want to update a customfield of type "date" with the value of "sprint end date"?

Hello @Nir Haimov 

Yes. For all the issues (that have a sprint) inside one certain project .

Nir Haimov Community Leader Feb 28, 2019

Hi @Mihai Mihai 

Instead of creating customfield and than a script to update that customfield.

Simply create scripted field with script runner, in the scripted field template, choose "Date Time".

Copy paste this script:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprint = customFieldManager.getCustomFieldObjectByName("Sprint")

//End Date
Date endDate = issue.getCustomFieldValue(sprint)?.endDate?.first()?.toDate()

ignore the errors if ther are any, it should work any way.

Put the scripted field in your "view issue" screen.

If your issue have sprint, the scripted field will show you the "end date" as you wanted.

Hi @Nir Haimov 

 

Thank you for the suggestion. I should have mentioned earlier that we already have a date field created, and we want that existing one to get values based on the sprint date.

 

I know this complicates things.

 

Thank you!

Hi @Mihai Mihai 

OK, you will have to tell me if this customfield is of type "date" or "date time" this is a big difference.

Please check to be sure and et me know, i will help you

0 votes
Answer accepted

Hi @Nir Haimov 

When looking for it in custom fields, it appears as: Date Picker . 

Example of values from an issue that has it filled in: 1/Apr/19 . 

 

Thank you!

Nir Haimov Community Leader Mar 02, 2019

Hi @Mihai Mihai 

Here is the complete code:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprint = customFieldManager.getCustomFieldObjectByName("Sprint")
def changeHolder = new DefaultIssueChangeHolder();
def myCustomField = customFieldManager.getCustomFieldObject("customfield_12000")

//End Date
Date endDate = event.issue.getCustomFieldValue(sprint)?.endDate?.first()?.toDate()


if (endDate != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(endDate);
cal.set(Calendar.MILLISECOND, 0);
log.error(new Timestamp(endDate.getTime()));
log.error(new Timestamp(cal.getTimeInMillis()));

myCustomField.updateValue(null, event.issue, new ModifiedValue(event.issue.getCustomFieldValue(myCustomField), new Timestamp(cal.getTimeInMillis())),changeHolder);
} else {
myCustomField.updateValue(null, event.issue, new ModifiedValue(event.issue.getCustomFieldValue(myCustomField), null),changeHolder);
}

Just change "customfield_12000" to your custom date field.
And it will work perfectly.

Put it in Listener for any "issue update" event

Thank you very much @Nir Haimov  , it works great!

@Nir Haimov 

I am trying to copy Sprint Enddate to issue customField of type DateTime picker field, I am using below two ways it's not working, could you please correct me 

Approach 1:

def latestSprintEndDate = customFieldManager.getCustomFieldObject("Latest Sprint End Date")

Timestamp tsFormat = (Timestamp) issue.getCustomFieldValue(sprint)?.endDate?.first()?.toDate()
Date csNewDateValue = new Date(tsFormat.getTime() + 15*24*60*60*1000);

latestSprintEndDate.updateValue(null, epic, new ModifiedValue(epic.getCustomFieldValue(latestSprintEndDate), (Object)csNewDateValue),changeHolder)

 

Approach 2: your approach

Date endDate = issue.getCustomFieldValue(sprint)?.endDate?.last()?.toDate()

log.error "Sprint endDate ${endDate} Sprint Name : ${sprintName.toString()}"

if (endDate != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(endDate);
cal.set(Calendar.MILLISECOND, 0);
log.error(new Timestamp(endDate.getTime()));
log.error(new Timestamp(cal.getTimeInMillis()));

latestSprintEndDate.updateValue(null, epic, new ModifiedValue(epic.getCustomFieldValue(latestSprintEndDate), new Timestamp(cal.getTimeInMillis())),changeHolder);
} else {
latestSprintEndDate.updateValue(null, epic, new ModifiedValue(epic.getCustomFieldValue(latestSprintEndDate), null),changeHolder);
}

2020-06-23 08:31:26,741 ERROR [runner.ScriptBindingsManager]: Sprint endDate Tue Jun 23 10:46:00 PDT 2020   Sprint Name : TPK Sprint 1
2020-06-23 08:31:26,745 ERROR [runner.ScriptBindingsManager]: 2020-06-23 10:46:00.0
2020-06-23 08:31:26,745 ERROR [runner.ScriptBindingsManager]: 2020-06-23 10:46:00.0
2020-06-23 08:31:26,747 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2020-06-23 08:31:26,747 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$2.call(Unknown Source)
 at Script1884.run(Script1884.groovy:92)

I'm trying to do the same using the provided script, but I'm getting an error:

Schermafbeelding 2020-10-01 om 11.23.12.png

Not sure what to change in order to make the script work.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

82 views 0 4
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