Dear All,
I am quite new to Jira / Confluence and I am not from development background.
I need to set an Automatic date for Duedate for issues = 5 days after creation of Issue should be DueDate, Should exclude Saturdays and Sundays.
I used a expression / Code from blog as below, but got error messages. To be honest I don't know anything about programming.
Used expression
issue.setDueDate (new Timestamp (cal.getTimeInMillis() + 5 * 1000 * 24 * 60 * 60))
Error message
Unable to resolve class Timestamp @Line 1, column19
I am using Jira v7.13.3
Could you please help and guide
Hi there
Do it with a Scriptrunner Postfunction.
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.getIssueManager()
def creation = issue.getCreated()
def daysToShift = 5
def newDueDate = creation + daysToShift
def dayOfWeek = newDueDate.getDay()
switch (dayOfWeek) {
case 0 : newDueDate = newDueDate + 1 // sunday
log.debug('Adding 1 day to Sunday')
break
case 6 : newDueDate = newDueDate + 2 // saturday
log.debug('Adding 2 days to Saturday')
break
}
issue.setDueDate(newDueDate)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
log.debug(issue.key+': Due Date has been set to ' + newDueDate)
If it works, you can remove the debug level in production by changing level.DEBUG to level.WARN
@Leonard Chew - Thank you for all the information, I just a beginner - Could you please send some screen shots on steps I need to follow to get this Implemented.
I tried below option but didn't know how to proceed to next step.
I created a transition in workflow as custom
I also got below error messages in console
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, if you lack knowledge of jira-administration basics, it might be wise to persuade your manager to give you an administration course, before you work with scripts.
That said, here are the answer to your questions:
1) General: The script will not work if you paste it in to the script console, as the console does not know on which issue it should run on.
In a postfunction-script, the issue is automatically set to the issue currently being transitionend (created in our case).
2) Do NOT create a new transition. This postfunction should run on the initial "Create"-Transition, which is the line from the circle to the first status. The script automatically sets the due date when an issue is created through this workflow.
Here are some screenshots pasted together to get it to work:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leonard Chew - Thanks a lot for your support, I was able to complete the steps. But I don't see Due Date getting filled in Automatically.
Is there any additional steps I need to complete.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Vijaya Kumara Create an Issue (one that is created by this workflow). The script will be executed and you will see the logs (of the last 15 executions) in the screen you pasted above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leonard Chew - Yes I did create couple of Issues which are using the Workflow where Script was saved using Steps explained by you.
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.
@Leonard Chew - I have one more request, Now Due Date is created Automatically as 5 days after Issue creation. But this overwrites even If I fill a Due date while creation of Issue, can we set this option only to Issues which are missing Due Date information?.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if (issue.getDueDate()) {return}
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.
The code snippet exits the script if due date is set.
If you administer scripts, you will need to be able to read it at least a little bit, so try to figure out where it belongs. Try it out in different places on your testing system. You can use
log.debug('My Information')
to help get information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where exactly did you try the expression that you mentioned above?
You would need an app/add-on like ScriptRunner for doing this.
Ravi
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.