Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Dynamically set Due Date depending on Day of Week.

Hello. Can someone do a quick look over on this listener I built?

Purpose: Automatically set the due date when an issue is created. Due Date set is based on which day of the week the ticket was created.

Example: if it was created on a Monday AND does not contain a specific label, set Due Date to Now + 5 days. If the ticket is created any other day of the week AND does not contain a specific label, set Due Date to Now + 6 days.

Here is my listener:

import java.sql.Timestamp;
import java.util.Date;
import java.util.*;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import org.apache.log4j.Category;
import com.atlassian.jira.issue.MutableIssue;
import java.time.LocalDate;
import java.text.SimpleDateFormat;


def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.INFO)

Issue issue = event.issue;
MutableIssue myIssue = issue as MutableIssue;
Set issueLabels = issue.getLabels();


boolean containsLabel = false;
Date date = new Date();
long time = date.getTime();
log.info "time = " + time.toString()

issueLabels.each { label ->
if (label.toString().contains("exampleLabel")){
containsLabel = true;
log.info 'containsLabel = ' + containsLabel.toString()
}
}

log.info "Existing Due Date = " + myIssue.getDueDate().toString()


Calendar cal = Calendar.getInstance();
String createdDate = issue.getCreated().toLocalDateTime().format(java.time.format.DateTimeFormatter.ofPattern("yyyy/MM/dd HH:MM"))
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:MM", java.util.Locale.ENGLISH);
Date myDate = sdf.parse(createdDate.toString());
sdf.applyPattern("EEEE");
def String sMyDate = sdf.format(myDate);
log.info 'Created Date = ' + sMyDate.toString();


if ((sMyDate.toString().contains('Monday') || sMyDate.toString().contains('Sunday')) && issue.issueType.name == "Task" && containsLabel == false && myIssue.getDueDate().toString() == 'null') {
myIssue.setDueDate(new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60));
log.info 'dueDate = ' + myIssue.getDueDate().toString()
}
else if ((!sMyDate.toString().contains('Monday') || !sMyDate.toString().contains('Sunday')) && issue.issueType.name == "Task" && containsLabel == false && myIssue.getDueDate().toString() == 'null') {
myIssue.setDueDate(new Timestamp (cal.getTimeInMillis() + 6 * 1000 * 24 * 60 * 60));
log.info 'dueDate = ' + myIssue.getDueDate().toString()
}

 

I am able to see the 'dueDate = value' portion in the logs and it is not null, meaning the dueDate variable has been set. However, the issue's Due Date never actually updates. So something must be wrong with:

 

myIssue.setDueDate( new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60 * 60))

 

1 answer

1 vote
Antoine Berry Community Leader Apr 30, 2019

Hi @Michael Schultz ,

Kindly try this snippet to set due date according to current day : 

Calendar c1 = GregorianCalendar.getInstance();
c1.setTime(new Date())
if (c1.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY && !containsLabel){
c1.add(Calendar.DAY_OF_MONTH, 5);
}
else if (c1.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY && !containsLabel){
c1.add(Calendar.DAY_OF_MONTH, 6);
}
issue.setDueDate(c1.getTime().toTimestamp())

Antoine

@Antoine Berry Thanks for this solution. This works as did my solution before. However, I still can't get it to work in one project. It works in my test project. I've checked permissions, Screens, Field Config and I don't see any difference. 

Any idea why I just wouldn't be able to change a specific project's Due Date when it works in another? Schedule Issues permission is set correctly by the way.

Antoine Berry Community Leader May 02, 2019

Hi @Michael Schultz , 

Maybe check the workflow. Especially check the order of the postfunctions in the "Create Issue" transition, make sure your script is ran after the "Creates the issue originally.".

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

171 views 6 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you