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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @G Sunil Kumar ,
add the class
import com.atlassian.jira.event.type.EventDispatchOption
sorry.
And tell me something.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.