Trying to use smart values to update labels for due date
Asked by Tyler Tate:

I am at my wit's end here. I have been trying to write a very simple automation that can update an issues label when its due date has been changed. The format is MMMM-yyyy for the label based on due date. All I want to do is if an issue has its due date updated that 1 of 2 things will happen.

Let's say due date is 9/1/2024.

1. If no due date exists then that's really easy to add a new label for that.

2 (where I'm stuck). Let's say that I already have a label of September-2024 but now my due date update to 10/7/2024. I want a new label of October-2024 to be created and old label of September-2024 to be removed.

I was doing a basic When: Value changes for Due date Then edit issue fields Labels.

Adding a new label works fine with:

{{issue.duedate.format("MMMM-yyyy")}}  

but where I'm struggling is removing the old. I've tried the below but I can't seem to figure out what I'm missing.   

{{issue.labels.match("\^(January\|February\|March\|April\|May\|June\|July\|August\|September\|October\|November\|December)-\\\\d{4}$")}}  

{{issue.duedate.change.previous.format("MMMM-yyyy")}}  

Any help to point me in the right direction would be great!


Answers:
author: Tim Kopperud
body: Hi [@Tyler Tate](/t5/user/viewprofilepage/user-id/5568674), welcome to Altassian community.

You should treat labels as a list by using the syntax as described here [Jira smart values - lists \| Automation for Jira Cloud and Data Center \| Atlassian Documentation](https://confluence.atlassian.com/automation/jira-smart-values-lists-993924868.html)

```
{{#labels}} {{/}}
```

Secondly, do not try to change the label found, but first remove it from the list and then you add the new label.

Hope this guide you in the right direction.

#### EDITED: {#toc-hId-351416049}

A simpler approach that you might try is something like this:

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

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

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

Use **ADDREMOVE** option when editing the Labels field (ref yellow).

ITimK.

comments: author: Tyler Tate
body: Thanks a ton! I had to make a small modification to make it keep existing labels all I did there was change 'exactly matches regular expression' to 'contains regular expression' and then add a final action to add the new duedate after everything is done.

Great to start the day with this after hours of frustration!


author: Bill Sheboy
body: Hi [@Tyler Tate](/t5/user/viewprofilepage/user-id/5568674) -- Welcome to the Atlassian Community!

Adding to the other suggestions...

Rather than checking if the old label is present with the regular expression, why not just use the changelog entry to get the prior value, and always remove the label. If it is not present, it will not throw a rule error.

Kind regards,  
Bill


author: Rilwan Ahmed
body: Hi [@Tyler Tate](/t5/user/viewprofilepage/user-id/5568674) ,

Welcome to the community !!

You can create rule as below also.

in 1st step, keep the value for labels as blank

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


Tags: cloud

jira-cloud