Forums

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

Script fragment to prevent issue movement in case a field has a value

Mihai Mihai
Contributor
March 8, 2019

Hello,

 

I have the following script that I would like to use in "Script Fragments", provided by scriptrunner.

 

It's purpose is to prevent the "Move" issue button from appearing on the "More" option list, when a certain select list field has a certain value:

 

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def ReqProject = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Requesting Project")
def ReqProjectValue = issue.getCustomFieldValue(ReqProject)
def project = issue.getProjectObject().getKey()

return !(ReqProjectValue == "Solution1" && jiraHelper.project?.key in ["TP"])

 

 

I'm not sure what the problem is, as it is not throwing any errors, but it also does not hide the "Move" option, for that project, when the field 'requesting project' has that certain value.

 

Please let me know if you have any suggestions.

1 answer

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Champion
March 8, 2019

Hi,

Script fragment does not seem really consistent. 

However I had success on my end by not using return in the last line, and it worked after a few updates.

I would advise to store the condition in a variable and log it :

boolean condition =  !(ReqProjectValue == "Solution1" && issue.getProjectObject().getKey() == "TP")

log.error("condition : " + condition)

condition

(Notice I changed the code for the project key, I don't know if that was an issue but this is working for me)

Then load a new issue on another project.

Suggest an answer

Log in or Sign up to answer