You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
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.
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.