Hi,
I am new to using Jira automations, and I am trying to use a Webhook-triggered automation rule to populate custom fields of a sub-task using the json sent through.
Each json sends a list of dictionaries (within "results") and I need to:
For each dictionary, populate the custom fields using the attributes list of dictionaries as highlighted in bold the example below:
payload = {
"event": "xxx",
"checkResults": [
{
"id": "xxx",
"name": "xxx",
"attributes": [
{
"id": "xxx"
"name": "xxx"
"label": "xxx"
"value": ["value1"]
},
{
"id": "yyy"
"name": "yyy"
"label": "yyy"
"value": ["true"]
},
{
"id": "yyy"
"name": "yyy"
"label": "yyy"
"value": ["true"]
}
],
"outcome": "pass"
},
{
<<<<<dict no. 2>>>>
}
}
So far, my rule creates a smart value called "checkResult" which represents each dictionary within the "checkResults" list shown above (assume dict no. 2 is the same as the first one).
Here is a look into the Create Subtask action:
So currently I am using .get(0) and .get(1) to get attributes xxx and yyy. I was wondering if I could use some sort of logic like custom_field_x = "value" where "name" = "xxx". However, I cannot nest another loop within the "For each checkResult list item" branch.
Please let me know if I need to provide further explanation 😅 Many thanks in advance!
Hi @Rachel Alexander -- Welcome to the Atlassian Community!
For automation rule questions, context is important for the community to help. Please post the following:
Until we see those...
You describe this:
So far, my rule creates a smart value called "checkResult" which represents each dictionary within the "checkResults" list shown above...
How are you creating that smart value: with Create Variable, with Create Lookup Table, etc.?
If you are parsing the results directly, you can nest iterators, such as from the {{webResponse}} to dynamically build your JSON expression for creating the Subtask:
{{#webResponse.body.checkResults}}
{{#attributes}}
...use the attributes to dynamically build the JSON
{{/}}
{{/}}
I recommend building that first and storying in another Created Variable to help with logging and testing.
If you are using a Lookup Table, you could use the entries function to help iterate what has already been parsed. Please review this article to learn more about that technique: https://community.atlassian.com/forums/Automation-articles/Update-Create-lookup-table-action-improvements/ba-p/2427798
Kind regards,
Bill
Hi Bill,
Thanks for the quick response!
Apologies, when I tried to insert images in the original message, there was an issue with the character limit. I realise now its because I copied and pasted the images in, so I've amended the original message 😅
I created the variable within the For each: Smart Value action. Is this the best thing to do? It also doesn't seem to run through all of the dictionaries, so maybe this is the root of that issue as well...
When you say dynamically build the JSON expression, what action would I put this in, or would this be in the Created Variable?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that additional information!
First, I note your JQL condition is using single-rather than double-quotes. I recommend changing those to avoid problems; I believe JQL is documented only supporting double-quotes.
Next, if I understand your scenario correctly, the "attributes" each contain:
And so in the Create Issue action, you may use dynamically-generated JSON from iterating the values. I am assuming the custom fields are all single-select options.
To avoid timing problems, create the dynamic JSON in a variable first, perhaps writing it to the log to confirm the structure.
{
"fields": {
{{#checkResult.attributes}}
"{{name}}": { "value": "{{value}}" } {{^last}}, {{/}}
{{/}}
}
}
Then use that variable as the JSON for the create as: {{varJson}}
The key to making this work is getting syntax correct for your specific, custom field types.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.