Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

DueDate updates based on a script

Hello,

 

I am trying to update value of the due date based on the priority selected. I have added a post function to enable the function but doesnt seem to work. Can anyone suggest why this is happening? I am using the below script.

 

Script:-

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.core.util.DateUtils
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.sql.Timestamp

 

def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
log.setLevel(Level.INFO)

String priorityName = issue.getPriority().getName();
if(priorityName == "High"){
issue.setDueDate(new Timestamp((new Date() + 1).time))
log.info("The time is " + priorityName)
log.info("The time is " + Timestamp)
log.info("The time is " + Date)
} else if (priorityName == "Highest"){
issue.setDueDate(new Timestamp((new Date() + 2).time))
log.info("The time is " + priorityName)
log.info("The time is " + Timestamp)
log.info("The time is " + Date)

} else if (priorityName == "Medium"){
issue.setDueDate(new Timestamp((new Date() + 3).time))
log.info("The time is " + priorityName)
log.info("The time is " + Timestamp)
log.info("The time is " + Date)

} else{
issue.setDueDate(new Timestamp((new Date() + 4).time))
log.info("The time is " + priorityName)
log.info("The time is " + Timestamp)
log.info("The time is " + Date)

}

 

Based on the logs the script is executing but the Due Date is still empty.

 

Regards,

Sunil

1 answer

1 accepted

1 vote
Answer accepted

The script is working fine on all transitions except the create transition. Is this a bug?

 

Regards,

Sunil

Hello,

sometimes issue.setDueDate

is not enough

I've recommend to finish the code with 

 

issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)

 

remember to add at the begining the classes

 

 

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

 

and also

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issueManager = ComponentAccessor.getIssueManager()

MutableIssue mutableIssue = issue

 

Best regards.

Hi @Juan José Marchal Gómez ,

 

Getting an error

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.core.util.DateUtils
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.sql.Timestamp
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser


def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issueManager = ComponentAccessor.getIssueManager()

MutableIssue mutableIssue = issue

issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)

String priorityName = issue.getPriority().getName();

if(priorityName == "High"){
issue.setDueDate(new Timestamp((new Date() + 1).time))
}
else if (priorityName == "Highest"){
issue.setDueDate(new Timestamp((new Date() + 2).time))
}
else if (priorityName == "Medium"){
issue.setDueDate(new Timestamp((new Date() + 3).time))
}
else{
issue.setDueDate(new Timestamp((new Date() + 4).time))

}

 

Getting an error as the method "issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)" cannot find matching method.

 

Regards,

Sunil

Hi @G Sunil Kumar ,

add the class

import com.atlassian.jira.event.type.EventDispatchOption

sorry.

And tell me something.

Hi @Juan José Marchal Gómez ,

 

The Due date  still not updated.

Hi @G Sunil Kumar 

 

issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)

 

this line is the last line of the code...

 

set there and try again, please.

 

Also that you can check is try the code in console. Do you know how to do it?

Yup I got it.

 

Thank You @Juan José Marchal Gómez 

 

It is working.

 

Regards,

Sunil

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS

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