I'm attempting to capture name-value pairs from an Incoming webhook event, and while most values in {{webhookData}} are a typical/expected JSON structure, the webhookData.audit.changes element is a an array, of two objects per element, where
first object is {"field_name":"<fieldname>"}
second object is {"value":"<value>"}
and it's not clear how I would parse this in Jira Automation. So far, I'm reviewing the Advanced Branching to assign {{webhookData.audit.changes}} to a variable, but I think there is some json parsing or list iterating needed after that, and either converting to name:value pairs in a new json object, or dynamically using Create Variable (although it seems we cannot dynamically create names there).
Example
"changes" : [
{"field_name":"Name", "value":"test4"},
{"field_name":"Description", "value":"<div class=\"user-content\"><p>desc</p></div>"},
{"field_name":"Workspace", "value":"OPTEM Templates"}
]
Any suggestions on how to convert the data so it can be accessed like this?
{{changes.name}}
{{changes.description}}
{{changes.workspace}}
Thanks ahead!
You appear to want to change the structure of the response within the scope of the rule, and I am unclear how that is currently possible. The closest you may get is with match() and regEx to access the fields.
To save you time...created variables and list filtering may not help with this use case either: I experimented a while back to create name/value pairs in a created variable for access later in rules, but got stuck as many of the functions cannot take a variable as a parameter...and...variables are still text and do not understand any other typing information (e.g. JSON)
Kind regards,
Bill
Thanks for the quick response @Bill Sheboy - really, I just want access to those values and then create a new Issue with them. For instance, how could one find the object where "field_name":"Name" exists, and pull the value from "value":"test4" (in this case, to set the Summary to "test4" when it calls Create Issue) ?
"changes" : [
{"field_name":"Name", "value":"test4"}
]
I'm not very familiar with Regex, but I'm guessing I would need to match "Name" or "field_name":"Name" to get an index, then refer to changes.get(n).value ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, this isn't pretty and I suspect it will get the "value" for a the field_name of "Name". Please reuse, as needed, and substitute each specific field's name for each usage.
{{webhookData.audit.changes.match(".*(\{.field_name.\:.Name.*\}).*").match(".*value.\:.(.*).\}")}}
How it works:
Unfortunately, the regular expression parser for rules does not appear to support escaping double-quotation marks, so I substituted the generic . (any character).
For more ideas on what to try to match, please look at this reference, which is what Atlassian says their parse is based upon: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Quick note for those who got here: A colleague of mine helped me figure out an alternative way to get at the value I was looking for. It's a slightly different scheme we're dealing with, but should apply for any webresponse.body json that has an array, and some way to get to it's id / value pair.
In json, it looks like this:
{
idea:
{
(...snipped...)
custom_fields:
[
{
id:(...snipped...),
key:jira_issue_key,
value: ABC-123
}
]
}
}
Using smart value iterational functions, we can pull that value and finally assign / use it!
{{#webResponse.body.idea.custom_fields}} {{#if(equals(key, "jira_issue_key"))}} {{value}} {{/}} {{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you soo much for posting this solution. I struggled a lot on this problem! Can't thank you enough!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm facing one issue with the above solution. I'm not able to put a {{smart value}} instead of "jira_issue_key"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe that is correct behavior and you would need another solution approach, such as the regular expression. Once the rule is processing inside of the iterator for {{#webResponse...}}...{{/}} the scope is narrowed to what is visible at that point. In Erin's example, {{key}} is visible. But in yours the {{smart value}} is perhaps at a different scope.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Bill Sheboy
I guess you are right. The scope maybe different. I thought maybe we can access issue details inside that loop.
I will try to implement the regular expression approach.
Thanks,
Sankalp
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Quick question as I have a similar issue.
I got it all and makes loads of sense but I can't get it to iterate over my structure.
Which action do you use to execute the iteration? Is it Advanced branching?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.