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