Validator for the Due Date to be Sundays only

Neta Knyazhansky Caspy November 28, 2022

Hi,

My project has a validator for certain issue types to make sure issues have a due date when changing the status to "In Progress".
I'd like the validator (or a different one) to also make sure that due date is only Sundays.

We have ScriptRunner.

Is that possible?

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Patrik Korovsky
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 28, 2022

Hello @Neta Knyazhansky Caspy

If I understand correctly, you would like the "Due Date" field to only allow dates that fall on a Sunday, correct?

Neta Knyazhansky Caspy November 28, 2022

Hey @Patrik Korovsky ,

Yes, you're exactly right.

Patrik Korovsky
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 28, 2022

I have no experience with ScriptRunner.

I propose an automation that sets the "Due Date" field to the next Sunday based on the input. The change is observable after a refresh.
Sundays.png

Automation setup:

  1. The trigger will be "Field value changed"
    monitor.png
  2. We will add an "If block" so that if we set the Due Date on a Sunday it will not be set to the next week's Sunday, but remains on the selected date. The Advanced compare condition will be: 
    1. {{issue.Duedate.plusDays(7)}} does not equal {{issue.Duedate.withNextDayOfWeek("SUN")}}
      ifblock.png
  3. The action will be an "Edit issue" and we will set the "Due date" to be a smart value "{{Duedate.withNextDayOfWeek("SUN")}}"

The full automation looks like this:
final.png

Neta Knyazhansky Caspy November 28, 2022

Thank you for such a detailed response, I appreciate it.

In this case, the due date doesn't have to be the following Sunday, it can be any Sunday.
Any ideas?

Patrik Korovsky
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.
December 2, 2022

Would you accept an automation that sets the Due Date to the previous Sunday if a date in the future is selected Mo-Sat?

If yes, I can create it for you as well with the check that Due Date is automatically set to the next Sunday if set in the past or present week Mo-Sat.

Logically this would make sense to me.
Unfortunately I could not find a validation/condition to bind this to in the workflow.

Neta Knyazhansky Caspy December 5, 2022

This would be a perfect solution.

If the due date is set to Mon-Sat, then it will automatically change to the *following* Sunday.

I'd very much appreciate your assistance. 

Patrik Korovsky
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.
December 5, 2022

You wrote that if the date is Mon-Sat, then it is set to the following Sunday.
In my previous comment I wrote that it would be set to the previous Sunday.,

My logic is that if the due date is set for, say, Friday, December 16, 2022, then it would make sense to me that it has to be done by that date.

  • If we set it to the following Sunday: 18 (+2 Days Due Date)
  • If we set it to the previous Sunday: 11 (-5 Days Due Date)

To meet the due date, we need to stay at -X or 0 days Due Date.

I see three options:

  • Always set the Due date to the next Sunday
  • Always set the Due date to the previous Sunday
  • Set the Due date to the closest day to input
    • Mo, Tue, Wed -> Previous Sunday
    • Thu, Fri, Sat -> Following Sunday

Conditions:

  • If current week is chosen, always set it to that week's Sunday
  • If we set to the previous Sunday, always check that it does not land in the past
Neta Knyazhansky Caspy December 5, 2022

The use case is that deployment is part of our DoD and we only deploy on Sunday, so even if the work is done Mon-Sat, the Story can only be closed after the deployment on the following Sunday.

Therefore, option #1 is the best - Always set the Due date to the next Sunday.

Patrik Korovsky
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.
December 5, 2022

In that case my previous detailed comment from 28th November is applicable. It works for any week not only the next Sunday (that was just an example I gave).

Result

  • Automation changes the date
    Duedatelog.png
  • Automation notifies the user of a change (Optional)
    Duedatecomments.png

Here is the full setup with a recommendation:
Duedatesetup.png

  1. Field value changed (Trigger)
    Duedatewhen.png
  2. Re-fetch issue data (Advanced action)
    1. (Optional, we need it so the automation can properly comment)
  3. Create variable (Advanced action)
    1. (Optional, we need it so the automation can properly comment)
    2. Choose a variable name (I chose "InputDate")
      1. Choose what your variable saves: {{Duedate.fullDate}}
  4. Create an if block where:
    1. {{issue.Duedate.plusDays(7)}} does not equal {{issue.Duedate.withNextDayOfWeek("SUN")}}
      Duedateif.png
  5. Edit (Action)
    1. Due date to "{{Duedate.withNextDayOfWeek("SUN")}}"
      duedateedit.png
  6. Re-fetch issue data (Advanced action)
    1. (Optional, we need it so the automation can properly comment)
  7. Add a comment (Action)
    1. (Optional)
    2. The comment will read: Hello [~accountid:{{initiator.accountId}}],
      You have set the due date to *{{InputDate}}*.
      Since the due date can only fall on a Sunday, the automation updated the due date to *{{Duedate.fullDate}}*.
    3. Note that the "InputDate" depends on the name you chose in step 3.

 

Final thoughts:

  • I recommend adding a comment so that everyone sees what is happening
    • You can set the comment to be visible only to a certain role, but keep in mind that the rule Actor is "Automation for Jira" which only has the "atlassian-addons-project-access" role
    • If you want to get around my previous point with a certain amount of elegance, I recommend creating a new user with a name similar to this one "Your Company name Automation" and giving it the role under which you want the Actor to comment
  • Certain smart values I have chosen to my liking, you might prefer a different format to the Due Date I selected, you can read more on formatting dates here https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/
    • I also set the automation to tag the user, if you prefer just the name, replace [~accountid:{{initiator.accountId}}] with {{initiator.displayName}}
  • I din't cover that if the due date is set before the current week, it will be set to Sunday of the current week. Let me know if you would appreciate that.

If you have any questions or are struggling with something let me know. I will be happy to help.

Neta Knyazhansky Caspy December 5, 2022

You are the BEST!

The only thing that isn't working is the InputDate in the comment, it looks like this:
"You have set the due date to **."

I guess something needs to be changed in step 3?
Any ideas?

Like Patrik Korovsky likes this
Patrik Korovsky
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.
December 5, 2022

Happy to hear this works for you. I had a lot of fun with this automation.

Can you please share how you approached the third step?
If I follow my example it should look like this:

  • Note that you have to specify the "Due Date" date format in the variable when creating it, not later on in the 7. step (that would not work)
    sunday.png

I can imagine that automating the visibility of comments (or creating a new account for this) can also be tricky, so if you get stuck, feel free to ask for help in that area as well.

Adding the comment automation (step 7.) so you have the full picture.
comment.png

Neta Knyazhansky Caspy December 5, 2022

I found what wasn't configured correctly.

I didn't realize the configuration is case-sensitive so the Variable name in step 3 didn't match the syntax in step 7.
I fixed it and it's working perfectly now.

I can't express my thanks to you in words!!

Like Patrik Korovsky likes this

Suggest an answer

Log in or Sign up to answer