Hi,
I'm trying to automate linking newly created Stories to existing Epics (issue type = "Projet") based on specific criteria:
Goal
When a new Story is created:
Run a JQL search to verify if an Epic ("Projet") already exists in the same project.
The Epic must have an Assets (Insight) field called "Liste des clients", containing the same client as the new Story.
The Epic's field "N° Article [Short text]" must contain the exact text of the Story’s summary.
If such an Epic exists, automatically set the Story’s parent field to the found Epic’s key.
Attempt #1 – Using JMWE "Set issue fields" post-function
Here's my initial script:
"{% set Client = issue | insightFieldValue('customfield_10205')
| first
| field('attributes.Name[0].value')
| default('') %}
{{ ('type = Projet and project = ' + issue.fields.project.key +
' and "Liste des clients" = "' + Client + '"' +
' and "N° Article[Short text]" ~ "\\\"' + issue.fields.summary + '\\\""')
| searchIssues(fields="key") | field("key") }}"
Run this post-function conditionally:"{% set Client = issue | insightFieldValue('customfield_10205') |first | field("attributes.Name[0].value") |default("") %}
{{ ('type = Projet and project = ' + issue.fields.project.key +' and "Liste des clients" = "' + Client + '"' +
' and "N° Article[Short text]" ~ "\\\"' + issue.fields.summary + '\\\""') | searchIssues(fields="key") | field("key") != "" }}
Runtime error:Cannot read properties of undefined (reading 'type')"
Attempt #2 – Using "Build-your-own" script + REST API PUT
My second attempt:
"{% set Client = issue | insightFieldValue('customfield_10205')
| first
| field('attributes.Name[0].value')
| default('') %}
{% if Client != '' %}
{% set ParentKey =
'type = Projet and project = ' + issue.fields.project.key +
' and "Liste des clients" = "' + Client + '"' +
' and "N° Article[Short text]" ~ "\\\"' + issue.fields.summary + '\\\""'
| searchIssues(maxResults = 1, fields = "key") | field("key") %}
{{ "/rest/api/2/issue/:issue"
| callJira(
verb = 'put',
params = { "issue": issue.key },
body = {
"fields": {
"parent": { "key": ParentKey }
}
}
) }}
{% endif %} "
Error received: Error: Unexpected response: 400
parent: expected 'key' property to be a string
Could you please help me
Any advice or example would be greatly appreciated.
Thank you very much!
Best regards,
Reda
Hi @Ahmed Saci
You are on the right track and are almost there.
I have a working solution to and I have tested it. Please try the one below and let me know if it helps.
You can make use of EBA on the "issue created" event or the post function of the create transition.
- Use the Set issue field post function. It would look like the image below.
Below is how the get the Epic key:
{% set client = issue | insightFieldValue("customfield_10300") | first | field("attributes.Name[0].value") | default("") %}
{% set matchingEpics = ("type = epic and project = " + issue.fields.project.key + " and \"Liste des clients\" = \"" + client + "\" and \"Article[Short text]\" ~ \"\\\"" + issue.fields.summary + "\\\"\"") | searchIssues(maxResults=1, fields="key") %}
{{ matchingEpics[0].key }}
Below is the condition:
{% set client = issue | insightFieldValue("customfield_10300") | first | field("attributes.Name[0].value") | default("") %}
{% set epics = ("type = epic and project = " + issue.fields.project.key + " and \"Liste des clients\" = \"" + client + "\" and \"Article[Short text]\" ~ \"\\\"" + issue.fields.summary + "\\\"\"") | searchIssues(fields="key") %}
{{ epics | length > 0}}
note:
You will have to change the custom field ID to your assets field and Article[Short text] to your field name. What I try to do is build the JQL and test it, and then try to copy it to the code, making sure that I am not missing anything.
If you would like assistance with a screensharing session, feel free to open a ticket with us https://appfire.atlassian.net/servicedesk/customer/portal/11
Hope it helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.