ScriptRunner Behaviour how to update value of custom field type checkbox

Roberto L
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2017

Hello Community,

I am trying to update the value of a custom field of type checkbox.

My usecase:

Every Epic has a custom field of type checkbox known as "Dev Reviewed" I want it so that once a user updates the value of "Dev Reviewed" in an Epic then it flows down and does the same for all the stories under that Epic. That way the user doesnt have to click on every individual Story and update it that way. 

I am utilizing a Behaviour that looks when the Custom Field "Dev Reviewed" is updated in an Epic and runs the following code:

//Utilize JQL to get all the issues under an Epic
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def query = jqlQueryParser.parseQuery("'Epic Link' = "+currentIssue)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

//Loop through all the Issues returned and modifies their custom field value type checkbox to "Yes"
results.getIssues().each { documentIssue ->


IssueService issueService = ComponentAccessor.getComponent(IssueService);
def optionsManager = ComponentAccessor.getComponent(OptionsManager);
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

Issue issue = issueService.getIssue(user, documentIssue.getKey())?.issue

CustomField customField = customFieldManager.getCustomFieldObjectByName("Dev Reviewed")

Options options = optionsManager.getOptions(customField.getConfigurationSchemes().first().getOneAndOnlyConfig());

def selectedOptions = options.findAll {
it.value == "Yes"
}.collect {
it.optionId.toString()
}
issueInputParameters.addCustomFieldValue(customField.id, *selectedOptions)


def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (update.isValid()) {
issueService.update(user, update)
}

}

The code inside the loop i found from another post in the community.

I am unsure how it works and have not got it to work for custom field. My custom field of type checkbox has only one value "Yes".

I managed to get this code to work when it comes to updating the out-of-the-box field Summary, but not for any custom fields.

Could someone point me to the right direction regarding this.

It is worth noting that I tested out the code and I am succesfully able to get my custom field, find the value inside, but not change it.

Furthermore, could someone explain how "options" work and how I can set the value of a checkbox custom field. selectedOptions is also very confusing to me. Could not find good documentation online for this.

Thank you!!!

-Roberto

1 answer

1 accepted

0 votes
Answer accepted
Roberto L
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 25, 2017

Hello Community,

I figured this out myself.

issueInputParameter takes two arguments, the id of the custom field you want modified and the id of the Options value you want.

Changed my code to the following and it worked:

*selectedOptions to "14192"

14192 = the id for value "Yes" in my custom Field.

-Roberto

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events