Hi Atlassian Community, looking for some help to set current date/time based on change of status.
Here is the sample script but does not seem to be working as expected.
Start Date and End Dates are both Jira date picker fields
import java.time.LocalDateTime
import com.atlassian.jira.issue.status.Status
def oldStatus = transientVars.oldStatus as Status
def status = ['To Do', 'Not Started']
if (oldStatus.name in status) {
issue.set {
setCustomFieldValue('Start Date', LocalDateTime.now())
setCustomFieldValue('End Date', LocalDateTime.now())
}
}
else { setCustomFieldValue('End Date', LocalDateTime.now())}
Hi @Mary Mark
Hi Florian,
I am using scriptrunner. Here's the modified version but still not populating dates.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you using a postfunction or a listener ?
Could you not use Automation for JIRA instead ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK if you are using a post-function issue.set should work, you may have error in your script or condition is never true.
If you are in a transition from 1 status to another why to you need to validate the previous status ? Also I would have use new Date() instead of LocalDate
About automation you could create 2 rule that use the Issue transition trigger, select the 2 status as From value and let Target status to empty. Then you could add an action to edit issue and select Start Date, use {{now}} as value
The second rule will be the same but you let emplty the from transition and the to transition in the trigger configuration. as action you select End Date and add {{now}} as value.
I do not really understant the logic of setting the same date in both field but this should do what the script is doing.
Reagrds
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have a simple agile workflow with the following statuses: Not Started, Triage, In Progress and Cancelled. All of these are "all to all" statuses.
When Cancelled status is offered from Not Started and Triage, set the Start Date and End date to current Date
When Cancelled status is offered from In Progress, set the End Date to current date.
That is the reason I'm checking for the old/previous status.
I tried the following using New Date() putting the code in postfunction but it still does not work as expected. No dates are being populated.
import com.atlassian.jira.issue.status.Status
import java.time.LocalDate
def oldStatus = transientVars.oldStatus as Status
def status = ['Triage', 'Not Started', 'Ready for Team']
if (oldStatus.name in status) {
issue.set {
setCustomFieldValue('Start Date', new Date())
setCustomFieldValue('End Date', new Date())
}
}
else {
issue.set{
setCustomFieldValue('Start Date', new Date())
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Could you try this script ? It has to be placed at the top of the postfunction list.
import java.time.LocalDateString previousStatus = issue.status.namedef status = ['Triage', 'Not Started', 'Ready for Team']if (previousStatus in status) {issue.set {setCustomFieldValue('Start Date', LocalDate.now())setCustomFieldValue('End Date', LocalDate.now())}}else {issue.set{setCustomFieldValue('Start Date', LocalDate.now())}}
Because the post-function is placed before the change are saved in the database, the previous status remain the current one.
Regards
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.