Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Smart Value returns empty value when used inside list

SB ITS Application Team September 19, 2023

Hi,

I am trying to use automation in JIRA Data Center (Software + Service Management) to fill an issue field from a list of templates depending on the request type. The list is fetched via REST call and is returned as a list of json objects.

The id to look for is derived from issue properties and written into an automation variable.

Iterating over the list works fine, as does accessing the variable value outside the list processing. 

When I try to access the variable (or any other smart value) inside the list processing loop, it only returns an empty value, so the check for the required template fails. 

For test purposes I just try to write the values into the issue description using the Edit Issue action:

Request: {{requestType}}
Issue key: {{issue.key}}

{{#webhookResponse.body.templates}}
Request: {{requestType}}
Issue key: {{issue.key}}
Name: {{name}}
{{#if(equals(name, requestType))}}
Matched
{{value}}
{{/}}
{{/}}}

This results in a description like this:

Request: Template 3
Issue key: TEST-9876

Request:
Issue key:
Name: Template 1
Request:
Issue key:
Name: Template 2
Request:
Issue key:
Name: Template 3
Request:
Issue key:
Name: Template 4

 How can I access the global values inside the list?

 

1 answer

1 accepted

0 votes
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.
September 19, 2023

Hi @SB ITS Application Team 

Once inside of an iterator, the only values visible are at that iterator's scope and lower.  Your use of {{requestType}} inside is becoming null, and so not matching.

For the scenario you show, two possible work-arounds are:

1) Rather than iterate over the webhookResponse, use a match() function to extract the data at each point in the Edit Issue action where you need template data.

2) Expand your webhookResponse into a created variable (with added delimiters), and then use match() or text functions on it to access the data.

For either of those, if you use the match() function approach, your regular expression will also need to be stored in a created variable, as I believe that is the only way to create a dynamic expression.

Kind regards,
Bill

SB ITS Application Team September 20, 2023

Hi Bill,

Thanks very much, that's what I suspected - I had hoped for a simpler solution :( 

Stand back, I'm going to use regular expressions...

Like • Bill Sheboy likes this
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.
September 20, 2023

A suggestion on regular expressions and automation rules: try the simplest thing which could work and test it.

The documentation for match() indicates the regular expression implementation is based upon the one for Java's Pattern class, but nowhere is it fully documented what does and does not work in rules.  Several community members have encountered problems with look-ahead and other features not working as they are documented in the Pattern class.

SB ITS Application Team September 20, 2023

After some hours of trying to get a match with an expression that definitely should match, and having whittled down the expression to "(.*)" for testing (still not matching...) I found out that match() will not take a created variable as pattern - the same pattern, put in as string literal, will match fine. Doh. 

I finally used something like myText.replace(myVariable,"GOTCHA").match("<somepattern>GOTCHA<somemorepattern").

It ain't pretty...still, at least it works.

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.
September 21, 2023

I am glad to learn you have something that works.

FYI that match() can take a single, created variable as a parameter (at least for the Jira Cloud version of automation).  And so when I have a dynamic, regular expression based on other fields, I first build the expression in a created variable and then use that in the match, like this:

{{issue.someField.match(varMySearchExpression)}}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.8
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events