DueDate updates based on a script

G Sunil Kumar December 22, 2020

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
G Sunil Kumar December 23, 2020

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

 

Regards,

Sunil

Juan José Marchal Gómez
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 23, 2020

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.

G Sunil Kumar December 23, 2020

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

Juan José Marchal Gómez
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 23, 2020

Hi @G Sunil Kumar ,

add the class

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

sorry.

And tell me something.

G Sunil Kumar December 23, 2020

Hi @Juan José Marchal Gómez ,

 

The Due date  still not updated.

Juan José Marchal Gómez
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 23, 2020

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?

G Sunil Kumar December 23, 2020

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