Populating the sprint field of a created issue depending on the due date
Asked by Guillaume Govers:

Hey Everyone,

I am working on a Jira Cloud instance, and I would like to be able to assign a Sprint to a created Epic automatically. This would be done by comparing the Due Date of the created Epic with the dates of active and future sprints. The correct Sprint will be chosen if the Due Date of the Epic is between the Start Date and End Date of the Sprint.

The Epic, when created, already has a Due Date. I want to avoid manually editing the Sprint field to fit the Due Date.

I have tried using both Jira Automation and JMWE to automate this but to no avail. I am unsure if there is a way to do this with these apps ?

Thank you for your help,

![Jira JMWE.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/219560i1D729680CFE906A6/image-size/large?v=v2&px=999 "Jira JMWE.jpg")![Jira Automation.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/219563i274BFA81B676AED3/image-size/large?v=v2&px=999 "Jira Automation.jpg")


Answers:
author: Bill Sheboy
body: Hi [@Guillaume Govers](/t5/user/viewprofilepage/user-id/4945148) -- Welcome to the Atlassian Community!

First thing, what problem are you trying to solve by doing this?

I wonder because epics are typically not assigned to sprints as they are larger work items, taking multiple sprints to complete, and so their child issues are assigned to sprints.

Regarding your use case and question, this might be possible, by either...

1. use a standard naming convention for sprints which is tightly coupled to date values, infer the specific target sprint by evaluating the issue's due date (through value date increments/adjustments) to dynamically build the sprint name, and then set the value
2. call the REST API to gather all of the sprints for the project/board and use smart value, list filtering to find the sprint to use

Kind regards,  
Bill

comments: author: Guillaume Govers
body: Hey [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

I appreciate that the way we use Epics is not the typical one. We are a non-dev team and an Epic is equal to an analysis that should be produced during a Sprint. This Epic has associated tasks (and not stories as seems to be the norm) that divide the work up. In the majority of the cases the Epic and related tasks will all be done in one sprint.

We have an integrated system where an external app automatically creates Epics with a populated Due Date. The idea is that instead of manually assigning these Epics to our Sprints this would be done automatically.

1. Not sure I understand your suggestion. Would Sprint names look something like this?

"Sprint XXX: ##Start Date##;##End Date##" Sprint 34:22/08/22;10/09/22

Would I then use the Smart Values in Jira Automation to deduce the dates of a Spriint from its title ?

2. I have never used the REST API but have been wondering if this would be required here. Would you happen to have an example of a similar API that I could base myself on?

Thanks for your help,

Guillaume


author: Bill Sheboy
body: For method #1: yes, I was suggesting a structured sprint name that could be created only using the date (and not necessarily the number). Let's say you pick an anchor starting date of 1 Jan 2022, and have 2 week sprints. You should be able to determine the correct sprint based upon the due date by rounding up to the next whole 2 week increment.

For the REST API usage (for #1 or #2), here is a great how-to article showing how to call such methods:

<https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828>

And the specific method you want is to get all the sprints for a board:

<https://developer.atlassian.com/cloud/jira/software/rest/api-group-board/#api-rest-agile-1-0-board-boardid-sprint-get>


author: Guillaume Govers
body: Hello, again [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

I have managed to configure two web requests with the Rest API.

The first one is a GET that returns all the sprints of my board, as you suggested.

The second one is a PUT that edits the sprint field of my trigger issue.

These two seem to work fine after some back and forth.

However, I still can't seem to find a way to differentiate sprints depending on the due date of the trigger issue. I have tried using the Jira Automation conditions to no avail. I have also tried using the Due Date smart value in the JSON of the web request, but they do not seem compatible.

![Follow UP Rest API.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/220188iF4113E5B45DD06DA/image-size/large?v=v2&px=999 "Follow UP Rest API.jpg")To my understanding, with the smart values, I should be able to access the start date of all sprints from my first web request and compare them to the due date. Or could I add an "if" function in the payload of my web request? It is still unclear to me how to achieve this distinction based on the due date.

Thank you for your help already, feeling quite proud to have used the REST API for the first time :)


author: Bill Sheboy
body: I believe you can do this with smart value list filtering: <https://community.atlassian.com/t5/Automation-articles/Filtering-smart-value-lists/ba-p/1827588>

For your web request response to gather all of the sprints, use the issue's due date and find the one where the due date is within the sprint's data range. Then use that sprint name (or id) as needed.


author: Guillaume Govers
body: Hello [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Have been dabbling in this, however every time I seem to have a smart value filter that should work I seem to get this error message:

"Error invoking method com.codebarrel.automation.api.component.smartvalues.objectwrappers.CollectionWrapper.Element.get(java.lang.String@2061000330) on com.codebarrel.automation.api.component.smartvalues.objectwrappers.CollectionWrapper.Element@1007599544:"

I am not sure how to solve it. I have found some similar errors that seem related to the use of plug-ins. This does not seem to apply here as I am using only classic Jira fields ?

I would appreciate any insight you have here. Thank you for your help,

Guillaume![Follow Up Rest.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/220656i01BF8A194BBEA024/image-size/large?v=v2&px=999 "Follow Up Rest.jpg")


author: Bill Sheboy
body: Perhaps the structure of the response does not match what you expect. Please first try running that REST API request by just pasting the URL into a browser. Then review the resulting response message to confirm you are getting the correct smart value layout.

**UPDATE**: After I experimented with this, I do not believe this can work with smart value, list filtering. Sorry for the bad solution idea.

First, the endDate value from the response needs to be converted from Text to a Date type for comparisons, leading to an expression like this:

{{#webResponse.body.values}}{{#if(endDate.toDate.isAfter(issue.duedate))}}{{name}}:{{endDate}}{{/}}{{/}}

Unfortunately...issue fields (and created variables) cannot be used inside of a function, *which is inside of an iterator* . Atlassian has already marked this defect as "Won't fix": <https://codebarrel.atlassian.net/browse/AUT-2430>

I also tried other functions instead of isAfter() and they were of no help. The problem seems again related to trying to do this in the filter.


author: Simmo
body: I don't think it is possible at the moment either [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313). I couldn't think of a way to do it.


author: Guillaume Govers
body: [@Simmo](/t5/user/viewprofilepage/user-id/3608665) [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

Thank you for your answers. I went with a simpler solution that requires the date of the next sprints to be added manually to the automation rule every few months. This won't be completely automatic but should work well enough for my use-case.

Thank you so much for your help and guidance,

Guillaume


author: Simmo
body: Hi [@Guillaume Govers](/t5/user/viewprofilepage/user-id/4945148),

What would be the event that would trigger the association between the epic and the sprint?

comments: author: Guillaume Govers
body: Hello [@Simmo](/t5/user/viewprofilepage/user-id/3608665) the trigger would be the creation of the Epic with a populated Due Date field.


Tags: addon-com.innovalog.jmwe.jira-misc-workflow-extensions

due-date

sprint