How to iterate a web response using match

Oliver Moore March 4, 2025

Hi,

I'm trying to iterate a list of possible custom field options from the Jira API

rest/api/3/field/customfield_10670/context/11056/option and match one of them against a regex to "select" it.

I can iterate the web response using:

{{#webResponse.body.values}}
{{.}}
{{/}}

 

Which gives:

 

{id=15022, value=AIR service, disabled=false}
{id=15024, value=Analytics Service, disabled=false}
{id=15161, value=Auth Service, disabled=false}
{id=15271, value=Comments and Evidences (CE) Service, disabled=false}
{id=15013, value=Content Service, disabled=false}
{id=15027, value=Control Service, disabled=false}

I want to pull the ID for the value matching "Content". I think I can use match like this from this post but I can't get it to work - I just get null

{{#webResponse.body.values}} {{value.match(".*Content.*")}} {{/}}

What am I missing? 

I can't tell if it's the regex or the syntax inside the loop

1 answer

1 accepted

1 vote
Answer accepted
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.
March 4, 2025

Hi @Oliver Moore 

Are you trying to only match on the value attribute within the values list?

If so, please try this:

{{webResponse.body.values.value.match("(.*Content.*)")}}

If instead you are trying to get the entire record from values where it matches, please try using list filtering on the value attribute to get the record:

{{#webResponse.body.values}}{{#if(exists(value.match("(.*Content.*)")))}}{{.}}{{/}}{{/}}

 

Kind regards,
Bill

Oliver Moore March 5, 2025

Hi Bill,

Thanks for this - I was looking for the 2nd option, but both examples worked perfectly.

I tweaked this slightly to just return the id

{{#webResponse.body.values}}{{#if(exists(value.match("(.*Content Service.*)")))}}{{id}}{{/}}{{/}}
 

Next I need to see if I can take that ID and "select" it. Hoping I can do this directly in the "advanced" edit issue, of if not, I'll assign it to a variable and push it that way.

Like Bill Sheboy likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events