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-9876Request:
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?
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
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.