Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

escalation service to close ticket and add a comment

Mary Mark October 3, 2022

Hello,

I am trying to create an escalation service that will close tickets greater than 7 days, sets the resolution to completed and adds a comment. In the workflow, when the close button (transition) is selected, a transition screen pops up and prompts user to select resolution and a value. The field resolution is a of type select list. The value to set should be "completed" I would like to bypass the transition screen and automatically set the status as closed, resolution as completed. 

The code I have is the following but it is not working. It mentions that 

Variable "customFieldManager" masks a binding variable of the same name. Please choose a different name for variable: "customFieldManager"

--------------------------------------------------------------------------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Resolution")
def cfConfig = selectCf.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find {
    it.toString() == 'Completed'
}
issue.setCustomFieldValue(cfSelect, value)
issueInputParameters.addCustomFieldValue(customField.id, option.optionId as String)
//issueInputParameters.setSkipScreenCheck(true)

CommentManager commentManager = ComponentAccessor.getCommentManager()

commentManager.create(issue, currentUser, 'status set to close, resolution is completed and ticket has been automatically closed.', true)

 

Thank you. 

1 answer

1 accepted

0 votes
Answer accepted
Aron Gombas _Midori_
Community Champion
October 4, 2022

The message means that a variable with that name is already "prepared" for your script! So I guess all you have to do is removing this line:

def customFieldManager = ComponentAccessor.getCustomFieldManager()

and the error should disappear.

Also, note that you don't actually use the variable "customFieldManager" anywhere in the script, so this line was useless anyway!

Mary Mark October 4, 2022

Hi Aron,

Thanks for your reply. I tried to remove the line but still getting errors. Please note that I am placing this code in the console in escalation services. 

The errors are as follow:

Cannot find matching method com.atlassian.jira.issue.customfields.manager.OptionsManager#getOptions(java.lang.Object). Please check if the declared type is correct and if the method exists.

 

[Static type checking] - Cannot find matching method com.atlassian.jira.issue.IssueInputParametersImpl#addCustomFieldValue(java.lang.Object, java.lang.String). Please check if the declared type is correct and if the method exists.
Possible solutions: addCustomFieldValue(java.lang.Long, [Ljava.lang.String;), addCustomFieldValue(java.lang.String, [Ljava.lang.String;), getCustomFieldValue(java.lang.Long), getCustomFieldValue(java.lang.String)

 

Please advise. Thank you. 

Aron Gombas _Midori_
Community Champion
October 4, 2022

The OptionsManager class does provide a getOptions() method:

https://docs.atlassian.com/software/jira/docs/api/8.0.0/com/atlassian/jira/issue/customfields/manager/OptionsManager.html

Groovy can't call it for some reason. Isn't this possible that your "cfConfig" variable is NULL?

Mary Mark October 4, 2022

Hi Aron,

Thank you very much for your feedback and your guidance. After playing with the code for a bit, I think I got what I want. Basically when a user clicks on the closed button, it prompts for the required field resolution and I want to set that value to completed. 

I updated it with the following and it works. What I'm confused is what is the difference between the above method getting the select list customfield: Resolution and performing a set value to: Completed. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager

def constantsManager = ComponentAccessor.getConstantsManager()
def resolution = constantsManager.resolutions.findByName("Completed")

issueInputParameters.setResolutionId(resolution.id)
CommentManager commentManager = ComponentAccessor.getCommentManager()
commentManager.create(issue, currentUser, 'This ticket has been in "Resolved" state for 7 or more days without an update. This ticket will be automatically moved to "Closed" state.', true)
I am still learning and appreciate all advice and guidance.
Thanks!


Like Aron Gombas _Midori_ likes this
Aron Gombas _Midori_
Community Champion
October 4, 2022

Great work! Please accept my answer above if it guided you to the solution.

Suggest an answer

Log in or Sign up to answer