Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation: use default if epic link empty

Paul Pasler
Atlassian Partner
December 3, 2023

Hi there, 

I have a rule using a value from the issues Epic link to set the a value of another field using automation.

Something like this, where "Bar" is an object type custom field with an array "list" in the epic 

{
"fields": {
Foo: {{issue.epic.Bar.list.asJsonStringArray}}
}
}

I tried to use an "OR (|)" like this "{{issue.epic.Bar.list.asJsonStringArray|[]}}", but I think this fails as "epic" is not set.

Any idea how to fix this?

1 answer

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2023

Hi @Paul Pasler 

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

Would you please clarify: are your two custom fields select list, multiple choice fields, or something else?

If they are, this is the syntax to set the field values with JSON: https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-select-custom-field

If you are adding values, versus just setting them, the logic would be more complicated as the current values need to be included first.

And for this type of field, you likely want to use asJsonObjectArray instead:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/#asJsonObjectArray-keyName-

Kind regards,
Bill

Paul Pasler
Atlassian Partner
December 4, 2023

Hi Bill,

sorry if any context information were missing. I tried to distill the problem, so it's easier to see the core of my issue. As this is a prototype, there is not much more context yet, but this:

Automation-Jira.jpg

The custom field is a Forge custom field of type object with two properties ("texts", "colors") including arrays of strings. The value from the Epic link should be copied to a newly created target issue. If an issue has an linked Epic, it works as expected. But if there is no Epic, it fails and says "No valid JSON" (I assume there is undefined or null). I want to set a default value in case there is no linked Epic.

I hope this clears things up a bit.

Cheers,

paul

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2023

Thanks for clarifying the scenario. 

First thing: I recommend confirming the smart value for your field in that expression.  Smart values are name, spacing, and case-sensitive, and the often do not match the display name on the issue views.  To confirm the smart values for your field, please check this how-to article: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

 

Next, I recommend using a rule condition (on epic link / parent) or a conditional expression to solve this: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

For example, with rule conditions like this:

  • if/else condition
    • condition: testing if there is an epic, parent
    • action: edit with the epic's fields (i.e., {{issue.parent.Maintance status... )
  • else
    • action: edit with the default

Or, it could use a conditional expression and do this in-line, in a single edit.  This shows doing this with a created variable to ensure the expression is parsed before it is used in the advanced edit.

  • action: create variable
    • name: varMaintenanceJson
    • smart value:
"Maintenance status" : {
"text " :
{{#if(exists(issue.parent))}}add your field JSON here{{/}}
{{#if(not(exists(issue.parent)))}}add your default value JSON here{{/}}
,
"colors" :
{{#if(exists(issue.parent))}}add your field JSON here{{/}}
{{#if(not(exists(issue.parent)))}}add your default value JSON here{{/}}
}
  • action: edit issue, using the pre-built {{varMaintenaceJson}}
Paul Pasler
Atlassian Partner
December 6, 2023

Hi @Bill Sheboy ,

thanks for the recommendations!

I went with the first suggestion, which is easier to maintain in my eyes.

The second approach did not work for me (although it should, according to the documentation...).

Cheers,

paul

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2023

I am glad to learn that helped.

For that second approach, prebuilding the JSON in a created variable can be challenging to get correct.  When doing this, I will write the variable to the audit log (and skip the edit) until I know my testing is complete.  Then I'll add the edit action.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events