Compare two date fields and add a label (ontrack-offtrack)
Asked by N?ria Rull Bassols:

Hi!

I hope you are well

I want to create a rule to track customer bugs.

We have a custom field that is called "target repair date" and I have an automation rule that updates the start and due date with the dates of the sprint.

I would like to set up two labels:

- Ontrack (duedate is less than "target repair date")

- Offtrack (duedate is greater than "target repair date")

I want to ensure that issues meeting their deadlines are appropriately tagged for easier tracking and management.

Now the label is added in all situations, I cannot add the ontrack and offtrack based on that comparison and I cannot find the rootcause.

Thanks a lot for your support!

![Screenshot 2024-05-30 at 18.08.28.png](https://community.atlassian.com/t5/image/serverpage/image-id/327023iB148BB2D257A7ED3/image-size/large?v=v2&px=999 "Screenshot 2024-05-30 at 18.08.28.png")


Answers:
author: Mark Segall
body: Hi [@N?ria Rull Bassols](/t5/user/viewprofilepage/user-id/4944556) - You'll need to change the conditions to If/Else conditions. As it stands now, it will pass/fail the first condition but never pass the second condition. It should look something like this:

* TRIGGER: Value changes for Due Date
* IF CONDITION: Compare two values
  * Edit Issue (Labels)
* ELSE CONDITION: Compare two values
  * Edit Issue (Labels)

Secondly, you mention that you have another rule that is setting the due date. This means that you also need to check the box on the **Rule Details** screen that enables other rules to trigger the new rule:
> Check to allow other rule actions to trigger this rule. Only enable this if you need this rule to execute in response to another rule.

comments: author: N?ria Rull Bassols
body: Thanks a lot [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) that worked!

What if I want to add another label but only if the due date is -10d or 15d of the Target repair date? Should I create variables?

This will be like: "at risk" issues

- Due date is -10d or 15d of Target Repair date

Thanks

![Screenshot 2024-05-31 at 11.44.16.png](https://community.atlassian.com/t5/image/serverpage/image-id/327179i2299D7499DB24652/image-size/large?v=v2&px=999 "Screenshot 2024-05-31 at 11.44.16.png")


author: N?ria Rull Bassols
body: I found the answer "minusDays."

Thanks a lot; I hope that can help other people, too.

![Screenshot 2024-05-31 at 14.15.02.png](https://community.atlassian.com/t5/image/serverpage/image-id/327189iDFDBAD40F11A64AB/image-size/large?v=v2&px=999 "Screenshot 2024-05-31 at 14.15.02.png")


author: N?ria Rull Bassols
body: Well [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) I was too quick to "sing victory" I have issues with At Risk conditions


author: Joseph Chung Yin
body: [@N?ria Rull Bassols](/t5/user/viewprofilepage/user-id/4944556) -

I agreed with what [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) stated, especially his mentioning of "enables other rules to trigger the new rule:"

Here is a reference link on how to properly troubleshoot automation rule from Atlassian -

<https://support.atlassian.com/cloud-automation/docs/debug-an-automation-rule/>

Hope this also helps you.

Best, Joseph Chung Yin

comments: author: N?ria Rull Bassols
body: Thanks a lot [@Joseph Chung Yin](/t5/user/viewprofilepage/user-id/396739) I'll have a look on the link provided :)


author: Kalyan Sattaluri
body: Hello [@N?ria Rull Bassols](/t5/user/viewprofilepage/user-id/4944556)

Before your first If statement, log the 2 dates.

To do that,

* go to Add Component -\> New Action -\> Log Action -\> Put in -\> Due Date is: {{duedate}}
* go to Add Component -\> New Action -\> Log Action -\> Put in -\> Target Date is: {{customfield_10521}}

Once you have added above 2 new steps, rerun the rule by changing the due date and share screenshot of your audit log so we can take a look at output.

Thanks!

comments: author: N?ria Rull Bassols
body: Thanks a lot [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) it worked :)


Tags: automation

cloud

custom-field

jira-service-management

jira-service-management-cloud

smart-value