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

Mapping the sprint ID to the sprint name via webhook request

Patrizia Heinzl March 29, 2024

Hello,

I need to map a sprint name -which is matching a specific string value- to its corresponding Id:

 

1. First, I get all sprints in my board: /jira/rest/agile/1.0/board/boardid/sprint 

Example of the webhook body:

{id=163608, self=xxx, state=closed, name=Sprintname1, startDate=xx, endDate=xx, completeDate=xx, activatedDate=xx, originBoardId=boardid, synced=false, autoStartStop=false}, {id=163650, self=xx, state=closed, name=Sprintname2, startDate=xx, endDate=xx, completeDate=xx, activatedDate=xx, originBoardId=boardid, synced=false, autoStartStop=false}

 

2. Now I'm trying to filter through the webhook body to extract a certain sprint id only. However I'm facing issues with the filtering query.

 

If I use this query: {{#webhookResponse.body.values}}{{name}}={{id}}, {{/}}

I get following output: Sprintname1=163608, Sprintname2=163650, Sprintname3=163641...

 

However I need to only print the Id of the Sprint which is matching a certain string value in its name.

e.g Sprintname2 = R44/23:

Output I need: 163650

 

I tried a few things, but nothing worked so far:

{{#webhookResponse.body.values}}{{#if(name,"R44/23")}}{{id}}{{/}}{{/}}

{{#webhookResponse.body.name}}{{#if("R44/23")}}{{id}}{{/}}{{/}}

{{#webhookResponse.body.values.name}} {{#if("R44/23")}} {{webhookResponse.body.values.id}}{{/}}{{/}}

 

Does anyone have an idea what could be wrong with above queries?

1 answer

1 accepted

1 vote
Answer accepted
Kalyan Sattaluri
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.
March 29, 2024

Hello @Patrizia Heinzl 

You are missing equals keyword in your first query.

{{#webhookResponse.body.values}}{{#if(equals(name,"R44/23"))}}{{id}}{{/}}{{/}}

 

Patrizia Heinzl March 29, 2024

Awesome, thank you so much! I tried a few variants with equals but never got it to work. This one works! Thank you very much!

Kalyan Sattaluri
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.
March 29, 2024

Great. I recall your other thread around the same topic.

Just to add, in this case you have hard coded R44/23 for the lookup, so it worked, but if you want to pass a smartvalue / variable in its place, maybe from the trigger issue, it will not work as in the context of the list iteration, smart values / variables dont resolve. 

If you need to extract ID based on variable look up, you need to save this webhook response in a variable and use a regex match to extract it.

Hoping I havent confused you and if what I am talking about does not apply, please ignore.

Patrizia Heinzl March 29, 2024

Ah thank you. Yes indeed I just tried a smart value and it does not work

Patrizia Heinzl March 29, 2024

But how do I get the regex match with the id? 

So you mean to create a variable out of the original webhook, correct?

And on this webhook use the regex match?

Kalyan Sattaluri
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.
March 29, 2024

Are you in Cloud edition or Data Center Edition?

Patrizia Heinzl March 29, 2024

Data center edition. I have the option to create variables.

Kalyan Sattaluri
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.
March 29, 2024

Sorry, Regex matching is black magic to me.

But you dont need to save it to a variable, I misspoke earlier. You can operate on the webhook response directly if needed... please see below thread for pointers. There maybe better posts, was just the first hit I found.

https://community.atlassian.com/t5/Jira-Service-Management/Search-in-Webhook-Response-and-get-a-specific-value-back/qaq-p/2029333

I think other folks maybe more experts who can help guide such a look up behavior.. so after researching, maybe posting another thread will help.

Reason I asked if DC or Cloud was.. In cloud, Jira has native branching which lets us do this For/Each check and we dont have to iterate manually like you did.. so Cloud would have been straight forward. DC is the tricky one, unfortunately.

Patrizia Heinzl March 29, 2024

Ok, thank you. Seems there is again an issue because I cannot match a smart value with a smart value :-( But thank you for your quick help!

Like Kalyan Sattaluri likes this
Kalyan Sattaluri
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.
March 29, 2024

If you wont mind, I will pitch my "not good" solution again from other thread.

If you were to create a task (for example) and just assign all open sprints to this one task  and you cancel this task immediately, so It wont show up in any board view or backlog.. It will solve the problem of making web request call to get sprint IDs. 

Because then, In your rule, after your trigger, you can do a lookup with JQL as.. Sprint = "Fix Version". This will return the canceled Task and you immediately have access to that Sprint ID.

Solves the problem without needing to go through complicated web request route,, when you look at the board, this canceled story wont show up so no one will be any wiser. 

Of course I know this is the not the right way but an option in back pocket.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events