Question: Issues with Conditional Label Creation in Jira Cloud Automation
Asked by Denny Ransom:

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 {#toc-hId--2124399987}

    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 {#toc-hId-363112846}

    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 {#toc-hId--1444341617}

**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!


Answers:
author: Trudy Claspill
body: Hello [@Denny Ransom](/t5/user/viewprofilepage/user-id/3395556)

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>

comments: author: Denny Ransom
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)   

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"
```


author: Trudy Claspill
body: 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?


author: Denny Ransom
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011)

1. Date picker

2. Done

3.

Log Actions

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/348374i7E7E058F22A7DA5F/image-size/large?v=v2&px=999 "image.png")

Log

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/348375i48E1BAC763F3C3F5/image-size/large?v=v2&px=999 "image.png")


Tags: cloud

jira-cloud