Setting data type custom field using advanced editing automation issue

Rafael Ibanhez
Contributor
November 5, 2024

I'm trying to use advanced editing automation and trying to set Data type custom field with some value from a lookup Issue OR null, but I can't figure why it does not work.

{ "fields": { "customfield_10640": null } }

This one works fine, it will clear the data custom field.

 

{ "fields": { "customfield_10640": "{{#lookupIssues}}{{customfield_10640}}{{/}}" } }

This also works fine, when the lookup issue filed is filled with some data it works. BUT when the look up issue is empty, it fails.

 

{ "fields": { "customfield_10640": "{{#lookupIssues}}{{customfield_10640|null}}{{/}}" } }

This does not work.

 

Tried all kind of tricks to go around but just can't figure why does not work.

3 answers

1 accepted

0 votes
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.
November 5, 2024

Hi @Rafael Ibanhez 

For a question like this, context is important for the community to help.  Please post an image of the complete rule and audit log details showing the rule execution.

Until we see those...

 

You appear to be using the Lookup Issues action (which returns zero-to-many issues) and setting the value into the same field for a single issue.  What is the type of the field, as I would not expect that to work except for a text field?

 

For your question about null / empty field handling, you could use the if / else structure you tried or instead use conditional logic to make the JSON dynamichttps://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/

For example, test if the field value exists (i.e., is not empty) and use that for the value; otherwise use null.

 

Kind regards,
Bill

Rafael Ibanhez
Contributor
November 5, 2024

Hello Bill. 

The automation I'm trying to do is exactly what I posted below. I want to set a data type field same as the one found in the lookup issue. I made sure only one is returned (used the lookupIssues.size. 

That is exactly my issue. conditional logic does not work in the advanced field edit. 

 

The test below did not work, Does not matter what I put on the Summary, the line is always skipped.

{
"fields": {
{{#if(equals(issue.Summary, "TEST"))}}"customfield_10640":null{{/}}

Here is the message LOG

log.jpg

 

The only conditional that seems somewhat works, its the "exists"

{
"fields": {
{{#if(exists(lookupIssues.customfield_10640)}}"customfield_10640":null{{/}}

Problem is that it always returns true, either custom field in the lookup is empty or not so its not helpful in this case.

 

work_around.jpg

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.
November 5, 2024

Perhaps try this:

{
"fields" : {

{{#if(not(exists(lookupIssues.first.customfield_10640)))}}
"customfield_10640" : null
{{/}}

{{#if(exists(lookupIssues.first.customfield_10640))}}
"customfield_10640" : "{{lookupIssues.first.customfield_10640}}"
{{/}}

}
}

You may need to experiment a bit, based on your specific field type: text, number, etc.

The default operator | does not work for all expression types, and so conditional logic is sometimes needed to elaborate a bit.

Like Rafael Ibanhez likes this
Rafael Ibanhez
Contributor
November 6, 2024

Hi Bill. 

This actually worked! Very creative. I was under impression that it would not work in the case of 0 issues found in the lookup, but it worked. Thanks 

Like Bill Sheboy likes this
0 votes
Rafael Ibanhez
Contributor
November 5, 2024

Also no working

 

{
"fields": {
{{#if(equals(issue.Summary, "TEST"))}}"customfield _10640" : null{{/}}

}
}

Of course I changed Summary to TEST, This line will not be interpreted by the rule and not execute, tried different approaches using if with no success. I think advanced editing is not so advanced 

0 votes
Rafael Ibanhez
Contributor
November 5, 2024

work_around.jpg

Work around would be using If statement but its hard to manage and automation gets too large. If I try to break into small pieces it cost much more processing power

Suggest an answer

Log in or Sign up to answer