I have a script which I would run from the console to move an issue from DONE to IN PROGRESS , as we have restricted users from moving an issue out of Done.
For now I am able to move the issue and clear the resolution, but unable to clear the Resolution Date, it still shows the date when the issue was last moved to DONE. Is it possible to clear the resolution Date as well ? But the resolution dates gets updated when I try and move the issue again to DONE
I have below section of code to clear the resolution,
if (issue.getResolution() != null) {
log.debug("Clearing the resolutionfield")
issue.setResolution(null)
issue.setResolutionDate(null)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Hi @Aisha M
For your requirements, I suggest using ScriptRunner's HAPI feature, which is simpler to manage and works as expected.
Below is a sample working code for your reference:-
if (!issue.resolution) {
issue.set {
setResolutionDate('')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
For this use case I have used the Custom Script Post-Funtion.
Below is a screenshot of the Post-Function configuration:-
Below are a couple of test screenshots for your reference:-
1. I am transitioning an existing issue to Done and setting the Resolution to Done as shown in th screenshot below:-
2. Once this issue transitions to Done as expected the Resolution date is displayed as shown in the screenshot below:-
3. Once I re-open the issue from Done, as expected the Resolved Date field is cleared as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ , Thank you for the comment !
For our scenario, we do not want to use a post function through the workflow, as moving out of DONE is restricted for users. So, for accidental moving of issues to DONE, we want to run a script from the console to move an issue (Feature, Program Epic or Portfolio Epic) from DONE to IN PROGRESS . .
I tried your suggestion as below from the console, but it did not clear the Resolution date . . Only able to clear the Resolution
SNIPPET OF CODE:
//Clear the resolution of the issue before transitioning
if (issue.getResolution() != null) {
log.debug("Clearing the resolutionfield")
issue.setResolution(null)
if (issue.resolution) {
issue.set {
setResolutionDate(null)
}
}
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue.setResolution(null)
if (issue.resolution) {
The problem is here. You already set resolution to null, then you check if resolution is not empty. It won't return true.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M
Your approach is incorrect. When using ScriptRunner's HAPI feature, there is no need to invoke EventDispatOption.
All you have to do to update the Issue's status from Done to In Progress and reset the Resolution Date is this:-
def issue = Issues.getByKey('MOCK-1') //Update the Issue Key
if (issue.resolution) {
issue.transition('In Progress') {
setResolutionDate('')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
Below is a screenshot of the ScriptRunner Console configuration for your reference:-
If the Issue is incorrectly transitioned to the Done status and you want to update it back to In Progress and remove the resolution date, all you have to do is run the script in the ScriptRunner Console.
It would be best if you looked into HAPI and simplified your approach as shown above.
For more examples of transitioning issues with HAPI, please refer to this documentation.
I hope this helps to solve your quesiton. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ Okay, it makes sense now :) . . I used the skip validator, conditions, permissions from the HAPI docs and was able to move the issue back to IN PROGRESS and thereby clear the resolution & resolution date.
But I have another question, I want to be able to do this action for three issue types (Feature, Program Epic & Portfolio Epic)
I am able to use HAPI for only the Feature issue type, because they have a back transition from DONE to IN PROGRESS, but is not available to users for moving , But for the other issue types, there is no workflow transition from DONE to IN PROGRESS. In that scenario, this does not work.
But, with my previous script, I was able to move any issuetype from DONE to IN PROGRESS along with clearing the Resolution, but was unable to clear the Resolution Date.
So, it that a limitation with using HAPI, it is necessary to have the transtions available in order to move the issue back ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M
In your last comment, you mentioned:-
But I have another question, I want to be able to do this action for three issue types (Feature, Program Epic & Portfolio Epic)
I am able to use HAPI for only the Feature issue type, because they have a back transition from DONE to IN PROGRESS, but is not available to users for moving , But for the other issue types, there is no workflow transition from DONE to IN PROGRESS. In that scenario, this does not work.
I'm a bit unclear what you mean by this. Please clarify: Are different workflows used by different issue types?
Generally, when you use the default workflow, i.e., the issue can transition to Done or In Progress from any other status.
Could you please share a screenshot of the workflow you are using for all the issue types?
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ , For compliance reasons, I cannot share screenshots from my environment.
But to give you an explanation, We have unique workflows for different issue types and each workflow has its own validators, conditions and permissions to navigate through the different statuses. In this case,
Feature Workflow - For EPIC issuetype
Standard Program Epic Workflow - For PROGRAM EPIC issuetype
Standard Portfolio Epic Workflow - For PORTFOLIO EPIC issuetype
Though the Feature workflow has a transition that go back from DONE to IN PROGRESS (Implementing), it cannot be moved back by users due to the some workflow validators.
But, the other two workflows, do not have any transition that goes back from DONE to IN PROGRESS (Implementing in my organization). Below is the workflow breakdown:
FUNNEL <----> ANALYZING <-------> READY BACKLOG <----------> IMPLEMENTING <-------->DONE
You can move back and forth between the other statuses, but once it goes to DONE, that's all, there is no transition available to go back.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M
If that's the case, you just need to include more filtration in the code to determine which status the issue should transition to. HAPI will works just fine with this.
Something like:-
def issue = Issues.getByKey('MOCK-1')
if (issue.resolution) {
if (issue.issueType.name in ['Bug', 'Task', 'Story']) {
issue.transition('In Progress') {
setResolutionDate('')
}
} else if (issueType.name in ['Portfolio Epic', 'Portfolio Epic']) {
issue.transition('Implementing') {
setResolutionDate('')
}
}
}
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ Thank you for the reply. I do not want the issues to move to different statuses, I want the capability to move all three issuetypes to "Implementing" status despite having unique workflow.,
Since, two of the workflows (for Program Epic & Portfolio Epic) do not have a transition back from DONE to IMPLEMENTING, the HAPI code did not work.
I want something that is equivalent to the below code
issue.setResolution(null)
issue.setResolutionDate(null)
issue.store()
Here is the full script for your reference: This works for all the three issue types despite having unique workflow - I am able to move the issues back to Implementing & clear the Resolution. But unable to clear the Resolution Date
def issueKey = "ABC-95"
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Validate if issue key is present
def issueManager = ComponentAccessor.getIssueManager()
MutableIssue issue = issueManager.getIssueByCurrentKey(issueKey)
if (issue == null) {
log.warn("Issue with key ${issueKey} not found")
return "Issue not found"
}
//Validate if issue is in 'Done' status
def doneStatuses = ["Done"]
def currentStatus = issue.getStatus().getName()
if (!doneStatuses.contains(currentStatus)) {
log.warn("Issue is not in Done or Deployed status")
return "Issue is not in Done or Deployed status"
}
//Clear the resolution of the issue before transitioning
if (issue.getResolution() != null) {
log.debug("Clearing the resolutionfield")
issue.setResolution(null)
issue.setResolutionDate(null)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
//Use the existing method in Script editor to move status
def transitionStatus = "Implementing"
setWorkflow.setWorkflowStatus(issueKey, transitionStatus)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_ Hi , Can I please ask a question, while using HAPI , instead of issue.transition, is it possible to use a status name instead , because that would fix my problem
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M
Sorry, been busy today with work.
After going through your previous comment, you mentioned:-
Since, two of the workflows (for Program Epic & Portfolio Epic) do not have a transition back from DONE to IMPLEMENTING, the HAPI code did not work.
Unless that status has a transition to the next status, e.g. Done to Implementing, you will not be able to Transition the issue. Whether you use your old approach or your HAPI, it will not work.
I'm not sure how this is working in your environment.
Even if I try your approach, i.e.:-
import com.adaptavist.hapi.jira.users.Users
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.StatusManager
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.issueManager
def statusManager = ComponentAccessor.getComponent(StatusManager)
def issue = issueManager.getIssueObject('ST-3')
if (issue.resolution) {
issue.setResolutionDate(null)
def inProgress = statusManager.statuses.find {it.name == 'Work in progress'}
issue.setStatus(inProgress)
issueManager.updateIssue(Users.loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
With the workflow where there is no way to return if it's Done, i.e.:-
It will not transition from Done. So I'm really not sure how you are able to do this using the old approach.
So to answer your latest question:-
Can I please ask a question, while using HAPI , instead of issue.transition, is it possible to use a status name instead , because that would fix my problem
As mentioned above, unless the Done status has a transition to which status you want to move it to, HAPI or even the old approach will not be able to fix your problem.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ Thank you for the clarification. In the old approach, I was calling for this method present on our editor while running from the console (we have a script to move issues to a different status)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Aisha M
In Jira, when you clear the resolution field, the resolutiondate field does not get cleared automatically, as this behavior is by design. The resolutiondate field is intended to keep a record of when an issue was resolved, and clearing the resolution field does not affect this historical timestamp. That's why there are plugins providing First Resolution Date, Last Resolution Date etc. However you can clear that with code (I would not recommend though)
In your code it won't enter the inner if block because you setResolution(null).
Here is how to do that by code.
issue.setResolutionDate(null)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk Thank you soooo much for checking back :)
So, you feel the below placement isnt the best to clear the resolution and the resolution date
if (issue.getResolution() != null) {
log.debug("Clearing the resolutionfield")
issue.setResolution(null)
issue.setResolutionDate(null)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem! :)
Yes, that will do the trick.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To be honest, that was my expectation.
I knew that Jira does not allow the resolutionDate to be cleared. However, after reading the comment by @Ram Kumar Aravindakshan from Adaptavist, I thought I might have been missing something and shared the code without testing, sorry.
I'm curious about how Scriptrunner's HAPI accomplishes this, though.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried incorporating the HAPI suggested into the script which I ran from the console, but it did not clear the resolution date. But, the example provided by @Ram Kumar Aravindakshan _Adaptavist_ seems to add it in the workflow postfunction. Not sure if that makes a difference, but it did not work for me to clear the resolution date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's hear from @Ram Kumar Aravindakshan _Adaptavist_
I am inquisitive about it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The ONLY way I am able to clear the resolution & resolution date is through the below modification . . (Came across a similar post on the community from two years ago & it came with warnings . . lol)
//Clear the resolution of the issue before transitioning
issue.setResolution(null)
issue.setResolutionDate(null)
issue.store()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far as I remember issue.store is an internal method which you should avoid using, and it is deprecated meaning that it will be removed in the upcoming versions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh no :( I dont understand why its this complicated to clear the Resolution Date . . Even through Automation nothing seems to clear the Resolution Date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
resolutionDate is a special field which is set automatically (not manually unlike other fields) and clearing it will also clear some history. This is what I know about it :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Tuncay Senturk , Hope you are well !! :) Sorry for the trouble . .
Can I please get your thoughts on this . . I have been seeing mixed info regarding the Resolution and Resolution Date, I was under the impression that Resolution Date would be cleared when the Resolution is cleared.
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.