Question: Issues with Conditional Label Creation in Jira Cloud Automation

Denny Ransom September 19, 2024

 

Hi everyone,

I’m attempting to conditionally create a dynamic label based on the value in a date field. Specifically, I’m parsing out the month to map it to a quarter. However, I can’t seem to get the equals function to resolve to true. It either resolves to false or throws an error and fails to resolve at all.

Right now I'm just writing log actions while I'm trying to get it to work.

In my testing, I’m using a September date. So, I should be able to compare it to some form of the number 9 and get it to resolve to true, but I can’t get it to work. Here are the permutations I’ve tried:

Parse the Date Field

Log action = "Target Start Month: {{issue.fields.Target Start.substring(5,7)}}, Year: {{issue.fields.Target Start.substring(0,4)}}"
Log - "Target Start Month: 09, Year: 2024"

Parse the Date Field as Number

Log action = "Target Start Month: {{issue.fields.Target Start.substring(5,7).asNumber}}, Year: {{issue.fields.Target Start.substring(0,4)}}"
Log - "Target Start Month: 9, Year: 2024"

Attempts to Compare Using the Equals Function

Resolves as FALSE

Resolves as: {{issue.fields.Target Start.substring(5,7).equals(09)}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7), 09)}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7).asNumber, 9)}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7).asNumber, 09)}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7).asNumber, '9')}}

FAILS to Resolve

Resolves as: {{issue.fields.Target Start.substring(5,7).equals('09')}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7), '09')}}
Resolves as: {{equals(issue.fields.Target Start.substring(5,7).asNumber, '09')}}

Any insights or suggestions on how to get this to work would be greatly appreciated!

Thanks in advance!

 

2 answers

2 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2024

Hello @Denny Ransom 

Welcome to the Atlassian community.

Rather than using all that Substring stuff you could use this to extract the numeric Month value from the date field

{{issue.Target Start.format("M")}}

Referring to the format command described here:

https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-format---

... and the linked page for Java Documentation of additional format options:

https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

Denny Ransom September 19, 2024

Hi @Trudy Claspill 

Thanks for the suggestion. 

Jira likes that even less. It doesn't even resolve to a 9 in the log. This is actually why I ended up going the substring route.



Log action = "Target Start Month format M: {{issue.fields.Target Start.format("M")}}, Year: {{issue.fields.Target Start.substring(0,4)}}"
Log - "Target Start Month format M: , Year: 2024"

 

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2024

Hello Denny,

1. What is the field type of Target Start? Is it a Date picker, or Date/Time picker?

2. Remove .fields from the smart value. It isn't necessary.

3. Add a Log action to just print {{issue.Target Start}} to confirm that a) you have the correct field name and b) It actually has a value.

I tested with a Date picker field and it correctly extracted the Month value as a number.

Can you provide a screen image of the actual Log action? Perhaps there is a typo in it?

0 votes
Denny Ransom September 20, 2024

Hi @Trudy Claspill 

1. Date picker

2. Done

3.

Log Actions

image.png

Log

image.png

Suggest an answer

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

Atlassian Community Events