You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi,
I'm using the Web Request component in Jira Automation to return a list of sprints for a specified board. I want to find the future sprint with the closest date to now.
The Web Request url is https://{{instance}}.atlassian.net/rest/agile/1.0/board/{{boardId}}/sprint?state=future
The Web Request returns the following body:
{
"maxResults": 50,
"startAt": 0,
"isLast": true,
"values": [
{
"id": 2,
"self": "https://[instance].atlassian.net/rest/agile/1.0/sprint/2",
"state": "future",
"name": "Sprint 2",
"startDate": "2023-10-26T11:00:00.000Z",
"endDate": "2023-11-02T11:00:00.000Z",
"createdDate": "2023-10-02T23:14:15.261Z",
"originBoardId": 1
},
{
"id": 3,
"self": "https://[instance].atlassian.net/rest/agile/1.0/sprint/3",
"state": "future",
"name": "Sprint 3",
"startDate": "2023-11-02T11:00:00.000Z",
"endDate": "2023-11-09T11:00:00.000Z",
"createdDate": "2023-10-02T23:14:19.908Z",
"originBoardId": 1
}
]
}
Note: the sprint id and name values above have been simulated. It won't be possible to determine the next sprint from the id or name, so startDate would need to be used.
I'd like to get the id of the sprint with the earliest future start date. If I first try to get the earliest date using the smart value {{webResponse.body.values.startDate.min}} it returns an empty string/value. {{webResponse.body.values.startDate}} returns the 2 start dates as text values. I think the problem is that the smart value doesn't recognize the date in the format returned by the Web Request so it can't use the min/max functions. I have tried converting the date text values to the Jira default format using {{webResponse.body.values.startDate.left(21).concat("+0000")}} but this still won't return a min/max.
Any ideas on how I can get the earliest sprint start date from this web response?
I got it working! I needed to convert the date first e.g. {{webResponse.body.values.startDate.toDate.min}}. I'm still not sure why I can't assign the values array to a variable as a list, so I will continue to use the webResponse object.
@Bill Sheboy thanks for your help. The info from the other post will be useful for the next steps.
Regards,
Greg
Awesome, and well done!
That is a good tool to add to the box; converting the value type, in place, before applying a list function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Greg McNamara -- Welcome to the Atlassian Community!
I recall doing this a while ago, however I cannot find my example rule. The trick was the returned web response was an array, not a list, and so needed to be parsed first into a field (or variable) for handling.
Please see this earlier community post which covers many of the ideas when @David Leal and I looked at his question.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Bill Sheboy !
I noticed that @David Leal had the same problem getting the min date, but he didn't need that in the end so it was unresolved. I still need to evaluate the dates, which are returned as text (whether directly from the webresponse or after assigning to a variable) but are not treated as dates by Jira Automation. To assign to a variable I'm just setting the variable to {{webResponse.body.values}}. Is there something else I need to do in order to have the text dates parsed and recognized as dates?
Regards,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy some more info on this issue: If I assign the values array to a variable, it doesn't behave like a list.
1) Create variable "futureSprints" and set to {{webResponse.body.values}}
2) Logging {{futureSprints.startDate}} gives me an empty output.
3) Logging {{webResponse.body.values.startDate}} gives me a list of start dates (in the raw text format from the json).
Should I expect the variable to be a list in this case?
Thanks,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Bill Sheboy , I managed to get the dates working, but still struggling to get the id of the sprint with the earliest date. I've tried the following:
1) Create variable nextSprintStartDate and set to {{webResponse.body.values.startDate.toDate.min}}
2) Create variable nextSprintId and set to:
{{#webResponse.body.values}}{{#if(equals(startDate.toDate,nextSprintStartDate))}}{{id}}{{/}}{{/}}
Step #1 works ok, #2 returns only sprints with no start date. I'm assuming it's because it's evaluating nextSprintStartDate as Empty in step #2.
Is there a way to pass that variable into #2, or do I need another method? I've tried an advanced branch to find the sprint and set a variable, but I can't use the variable value outside of the branch (where I need it).
Hope you can help.
Thanks,
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Further to the advanced branch method, I can use the variable outside of the branch, but in my testing it never holds the correct value. I think this is due to the non-deterministic problem you mentioned in another post (did that ever get fixed?).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm catching up on your posts/questions...even though it appears you have solved this one :^)
Variable usage: When you assign a web response to a variable, it becomes text and loses all object typing...including being an array or list. The work-around is to use split() later to convert back to a list.
A different approach, such as when you want to have multiple REST API function calls, is to store the response in a Lookup Table row. That new feature preserves the object typing, and so the value can be used later. This technique also helps when you want to use multiple Lookup Issues result sets together.
List iteration and scoping to see other data (e.g., issue fields, variables): My understanding from an Atlassian engineer and their posts is the team tried to fix this and was unsuccessful. My work-around for this is a bit complicated:
Branch processing: No, on the asynch/parallel processing behavior of branches. There is an open suggestion to add that capability to branches (i.e., wait until done) as exists for the Send Web Request action: https://jira.atlassian.com/browse/AUTO-32
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.