Forums

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

disable multiselect customfield options with script runner

Soporte Ferrovial October 7, 2021

I have this script to disable an option from a multiselect custom field

the customfield is "Support Group", usually 3-5 people selected 

we need to deactivate a list of people that can be or not selected in a large list of issues

for example we need to deactivate or unselect "Arturo Alcañiz Fidalgo -85348-"

I have no error in the script but it doesn't work:

1- the optionsavailable list returns all the options (+200)  in the customfield, not the selected options for this issue (3-5 selecteds)

2- after disabling the issue keep the previous customfield values

¿Can any one helpme to read an after add/delete, select/unselect values in a multiselect customfield?  

Thanks in advance

Here's the script===========================================


import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.web.bean.PagerFilter
//def log = Logger.getLogger(getClass())
import org.apache.log4j.Level

log.setLevel(Level.INFO)
// cargamos los elementos para manejar issues, proyectos y customfields
IssueManager issueManager = ComponentAccessor.getIssueManager();

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

//define the values you want to disable here
def optionsToDisable = ["Arturo Alcañiz Fidalgo -85348-"]

// The issues returned from that JQL will get altered
final searchQuery = "Support Group='Arturo Alcañiz Fidalgo -85348-'"

// Get some components
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueService = ComponentAccessor.issueService

// Perform the search
def query = jqlQueryParser.parseQuery(searchQuery)
def searchResults = searchProvider.search(SearchQuery.create(query, loggedInUser), PagerFilter.unlimitedFilter)

// Iterate all the results to update each issue
searchResults.results.each { documentIssue ->

//buscamos el id del issue
def issueId = documentIssue.document.fields.find { it.name() == "issue_id" }.stringValue().toLong()

//cargamos en el objeto issue el elemento
def issue = issueManager.getIssueObject(issueId);
log.info("Working on issue ${issue.key}")
log.info(searchQuery)

// definimos el customfield como cf

final cfName = "Support Group"
def optionsManager = ComponentAccessor.optionsManager
// def cf = customFieldManager.getCustomFieldObjects(issue).find { it.name == cfName }
def cf = customFieldManager.getCustomFieldObjects(issue).findByName(cfName)

// Value for a multi-select field will always be a list even if "None" is selected
def options = optionsManager.getOptions(cf.getRelevantConfig(issue))
def lista=options.toString()
log.info(lista)

def sb = new StringBuffer()

//disable options
options.each {
// log.info('options.each ' + it.value.toString())
if(optionsToDisable.contains(it.toString())) {
log.info('Disabling this option ' + it.value.toString())
sb.append("Disabling Option: " + it.toString() + "\n")
optionsManager.disableOption(it)
log.info(optionsManager.disableOption(it))
log.info(optionsToDisable.contains(it.toString()))
}
}

//ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(cf), [optionsToDisable]);
options = optionsManager.getOptions(cf.getRelevantConfig(issue))
lista=options.toString()

// log.info(sb.toString())

// return sb.toString()

}

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer