Forums

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

Set the value of the check box from another check box

Dante Labate June 19, 2018

I'm trying to pass the values from one checkbox to another, but it's not working

What am I doing wrong? (or missing)

 


def customFieldManager = ComponentAccessor.getCustomFieldManager()

def Equipment_new = customFieldManager.getCustomFieldObject("customfield_15721")
def Equipment_new_value = issue.getCustomFieldValue(Equipment_new).toString()

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def String myval2 = "${Equipment_new_value}"
def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15720") //Equipment_current
def cfConfig = cfSelect.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find
{it.toString() == "${myval2}"}
issue.setCustomFieldValue(cfSelect, value)

ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

 will run in a post function.

 

1 answer

0 votes
Mark Markov
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.
June 19, 2018

Hello @Dante Labate again. 

Change it.toString() to it.value

Dante Labate June 19, 2018

Hello @Mark Markov (again)

I already tested this change, but it also did not work.

The script does not show an error, but the field does not change.

Dante Labate June 19, 2018

I already tested with the option:
it.value in
(can have more than one option selected)

but not work..

Mark Markov
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.
June 22, 2018

You code seems a little bit strange. Why you need this many declaration with gstrings for the one value?

Try this code, ive added logging, when you will be test it, look in logs and see what exactly happen when script work.

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def Equipment_new = customFieldManager.getCustomFieldObject("customfield_15721")
def Equipment_new_value = issue.getCustomFieldValue(Equipment_new).toString()
log.error("Equipment value: "+ Equipment_new_value)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def cfSelect = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_15720") //Equipment_current
def cfConfig = cfSelect.getRelevantConfig(issue)
log.error("OPTIONS : "+ ComponentAccessor.optionsManager.getOptions(cfConfig))
def value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find
{it.toString() == Equipment_new_value}
log.error("FINDED OPTION VALUE: "+ value)
issue.setCustomFieldValue(cfSelect, value)

ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

Suggest an answer

Log in or Sign up to answer