Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Jira Automation: Sprint start dates returned from Web Request not recognized as dates

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?

2 answers

1 accepted

2 votes
Answer accepted

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

Bill Sheboy
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.
Oct 11, 2023

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.

1 vote
Bill Sheboy
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.
Oct 10, 2023

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.

https://community.atlassian.com/t5/Jira-Software-questions/Automation-Populate-start-due-date-from-Spring-Information/qaq-p/2278713

Kind regards,
Bill

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

@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

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

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?).

Bill Sheboy
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.
Oct 11, 2023 • edited

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:

  • The match() function applied to a list is not limited to scoping like list filtering
  • However match cannot directly take a dynamic, regular expression for the search
  • And so the work-around requires a few steps...
    • create a variable with your dynamic search expression; let's call that varSearch.  The tricky part is creating a regular expression that returns your desired data, such as .*({{nextSprintStartDate}}).* but with added data/search to return the entire record with the sprint id.
    • now iterate the list directly (or using split first to break up text) and apply the match: {{webResponse.body.values.match(varSearch)}}
    • finally use text functions on that result to extract the relevant fields

 

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

Like Greg McNamara likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events