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

how to iterate and compare webresponse values

ian April 3, 2022

Hello. Trying to use automation to get the Component Lead for a specified Component. 

I have a web request returning all project components. And I can iterate through them to display any attribute - using a log action with a statement like this:

{{#webResponse.body}} id: {{id}}, Name: {{name}} :: {{/}}

This returns a list of id and name pairs for each component.

But I'm clearly misunderstanding something because I cannot figure out how to compare values while I iterate the list. When I find a match I want to get the component lead accountId for that specific component.  I've tried so many variations now I'm not sure I remember them all - here are a sample:

{{#webResponse.body}}{{if(equals({{name}},"abc"), id: {{id}})}}{{/}}

{{#if(equals({{webResponse.body.name}}, "abc")}} id: {{webResponse.body.id}} {{/}}

This statement: {{#if(equals({{webResponse.body.id}}, 10060))}} "hello"{{/}}
generates this error: 

Error rendering smart-values when executing this rule:

Parameters not closed: ({{webResponse.body.id:
This statement: {{#webResponse.body}}{{if(equals({{body.id}}, 10060))}} "hello"{{/}}
generates this error:
Error rendering smart-values when executing this rule:
Failed to get value for if(equals({{body.id:
This statement: {{#webResponse.body}}{{if(equals({{id}}, 10060))}} "hello"{{/}}
generates this error:
Failed to get value for if(equals({{id
The webResponse.body appears to be a list and so I've been trying to use the logic outlined on this page:  Jira smart values - conditional logic | Cloud automation Cloud | Atlassian Support
Any ideas / pointers? Perhaps I'm asking too much?
Thanks.
 

2 answers

1 accepted

1 vote
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 3, 2022

Hi @ian ,

as far as I get the documentation right the smart values within the if/equal are without {{}}.

Please try the following approach and let me know if this works:

{{#if(equals(webResponse.body.id, 10060))}} "hello"{{/}}

 

Best
Stefan

ian April 5, 2022

Apologies for the delayed response. Thanks for pointing that out @Stefan Salzl Often takes a fresh pair of eyes to see the obvious mistake.

Unfortunately, while no errors, the command you suggested does not output anything. I also tried "10060" in case it was being treated as a string. Same result - no output.

But adding the iteration before the if statement and putting the "hello" in the then part of the if statement does output "hello":

{{#webResponse.body}}{{if(equals(id,"10060"), "hello")}}{{/}}

Replacing "hello" with the id field reference outputs the id value:

{{#webResponse.body}}{{if(equals(id,"10060"), id)}}{{/}}

Extending this I added a create variable action using this statement as the smart value:

{{#webResponse.body}}{{if(equals(id,"10060"), lead.accountId,)}}{{/}}

An audit log action following this shows that the variable got assigned the correct value.

I think I can now use this as part of my automation to automatically assign requests to the component lead which is what I was ultimately trying to do.

Thanks again @Stefan Salzl

Like # people like this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2022

AWESOME work man 🥰💪🏼🎉

Like ian likes this
0 votes
Kaysaff Tal April 14, 2023

@Stefan Salzl @ian Thanks for this post! it rescued my code.

I am stuck again :)

JSON structure:

{
"id":"id",
"self":"{{baseurl}}/rest/agile/1.0/sprint/{{sprint_1_Id}}",
"state":"active",
"name":"SAT Sprint 1",
"startDate":"2023-04-13T14:54:51.844Z",
"endDate":"2023-04-30T14:50:00.000Z",
"originBoardId":"originBoardId",
"goal":null
}

Got a valid web response, parsed it. now the goal is returning id the is marching name

this statement doesn't work (Smart variable - no error is given):

{{#webResponse.body.values}}{{if(equals(name,sprintFromCommentFiltered),id)}}{{/}}

 

Bus Hard coded:

{{#webResponse.body.values}}{{if(equals(name,"SAT Sprint 1"),id)}}{{/}} is working and returning the id as expected

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 14, 2023

Hi @Kaysaff Tal 

Could you please explain what you are trying to achieve from a functional/use case perspective? Without knowing any context it‘s hard to understand and/or find an appropriate solution.

Furthermore could you please share your automation rule?

and one more question:
where does „sprintFromCommentFiltered“ come from? Did you try to output this value to the audit log? Does it deliver the correct value you‘d like to compare against?

Best
Stefan

Kaysaff Tal April 15, 2023

@Stefan Salzl Sure thing.

I am send web request to our Jira instant and receiving back data on all sprints in a specific board.

response looks like this

Screenshot 2023-04-15 at 12.18.05.png

The sprint name Comes from a comment:

image.png

 

Which I parse:

image.png

image.png

Then trying to get the Matching SprintID

This works fine:

{{#webResponse.body.values}}{{if(equals(name,"SAT Sprint 1"),id)}}{{/}}

image.png

When i try to use the variable it fails

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2023

Hi @Kaysaff Tal 

It seems to me the problem is as soon as you start iterating over the webresponse the context within will always be the webresponse. So your variable would always try to resolve within the context of the webresponse (where there is no „property“ with that name). So to say (as far as I got it) the ouside variable could not resolve inside an iteration over a different object.

Have you tried to put the webresponse into a branch? You could do a forEach branch that will also iterate over your webresponse and you could control the required action via comparison in an if-condition (where you could use the variables smart value).

Best
Stefan

Like Kaysaff Tal likes this
Kaysaff Tal April 15, 2023

@Stefan Salzl Not sure what u mean:)

I think the Object is fine my issue is

this command:

image.png

where teste wquals

image.png

 

but when it runs hard coded:

image.png

the corrspondin ID is retuned,

The question if equals can identify variables i guess

 

Thanks

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2023

What I meant in my previous post:

- create an advanced branch to iterate over your webresponse (see screenshot):

image.png

- then add an advanced compare condition to compare the current iteration index against your created variable (in this case it´s possible to use a variable from outside of the branch which i guess is not possible when iterating over a smartvalue) - see screenshot:

image.png

- according to the if-comparison-condition the log action only fires when it´s true. so in my example above even if the branch iterates over all the sprints (which are about 9 in my example) the log action fires once.

image.png

 

Best
Stefan

Like Kaysaff Tal likes this
Kaysaff Tal April 15, 2023

@Stefan Salzl Thank u so much for the help here.

The issue is not finding the Sprint Name. is extracting  corresponding sprintID.

that is the issue i am stuck with

any thoughts? what i am missing?

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 16, 2023

Hi @Kaysaff Tal 

- This is the variable create upfront (in your case this would be what you extract from your issue´s comment - i just hardcoded the string in the variable)

image.png

 

- changed the branch to name "sprint" and it iterates over the values of the webresponse. This is capsulated in the name "sprint" that can be used as smart value in the branch:

image.png

 

- the condition then does the comparison of the current iterations SprintName against your variable (comment from issue):

image.png

 

- only if this matches I fetch the id from the webresponse. As my webresponse is capsulated in the variable "sprint" (configured in the branch configuration) I only add {{sprint.id}}

image.png

 

- wich results in the following:

image.png

 

Hope this describes what you are searching for.

Best
Stefan

Like Kaysaff Tal likes this
Kaysaff Tal April 23, 2023

@Stefan Salzl This is Amazing Solution!!!

it works perfectly!!! Alod understood how to use smart values in the process of trying to get this to work :)

One last struggle :)

after I branch out to the Smart Value:

Clone the specific story, assign it to the sprint we just found and move the Sub tasks that are still open.

Challenge: There is no branch out to cloned issue subtasks in the smart value branch

 

Screenshot 2023-04-24 at 8.10.53.png

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 28, 2023

Hi @Kaysaff Tal 

I dunno the whole use case behind it and furthermore the comunity is not a place posting requirements and get complete solutions but guiding you in a problem situation when you get stuck.

The main question was how to compare the result of a webresponse. As it seems for me this could be solved.

Furthermore:
(Talking as an experienced Scrum Master and Agile Coach) It seems you would like to clone open Stories from one sprint to another one. Why would you do that and not take the open story into the next sprint (which is commonly done and from my perspective the better way).

And technically moving the subtasks would mean a "Move issue" action which neither A4J nor RestAPI is capable of.

Best
Stefan

Kaysaff Tal May 3, 2023

@Stefan Salzl Actually community solved the issue.

Integration is working amazingly

Like Stefan Salzl likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events