JIRA Multi select checkbox customfield not getting updated properly Edited

I have a transition screen from which I am getting values(s) via a checkbox control,  I need to get these values and update them on another checkbox control in the issues view screen. I tried the below code and it worked but it doesnt set the checkbox option as selected but just shows the value like a editable text but when I clicked edit that option is not selected. 

def changeHolder = new DefaultIssueChangeHolder()
custField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(custField), platvalue),changeHolder)

I read that you need to use options , so I used the below code but it doesnt work

def optionsManager = ComponentAccessor.getOptionsManager()

def config = platRelOnAPIField.getRelevantConfig(issue)

def options = optionsManager.getOptions(config)

log.debug("Options of Plat rel on field in API:"+options) // This prints properly

def newOption  = options.get(7) //I want to set to the 8th checkbox just for example,this value prints properly

ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(platRelOnAPIField),newOption);

platRelOnAPIField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());


But I end up with this exception

 

java.lang.ClassCastException: com.atlassian.jira.issue.customfields.option.LazyLoadedOption cannot be cast to java.util.Collection

I am a newbie to groovy/jira apis , so please can someone help me to set the checkbox value properly for the customfield

Ive checked this

https://community.atlassian.com/t5/Answers-Developer-Questions/Set-custom-field-select-list-value/qaq-p/491158

but I still get the same exception :( 

 

Thanks !

2 answers

This widget could not be displayed.

A checkbox is an array of options - consider the list:

  • Red X
  • Greeen
  • Orange X
  • Blue X

There, it's got three options selected, so the value of the field is actually a collection of three.  You need to place the option you want into a collection of options to pass into the field, even if you only have one option to select.

Ok. Now I have a collection of options called platvalue which holds the values I want to update  and this statement works

custField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(custField), platvalue),changeHolder)

but it doesnt check the checkboxes for those values for my custField(one to be updated), here 

platvalue = issue.getCustomFieldValue(platRelOnField) //platRelOnField is the field from where I am getting my values to be set

 

 

That's a step forward, the next question is about what you see in the logs when this stuff runs.  If it's not updating anything, I'd expect an error message that at least hints at the problem.

I checked for any error in the logs, there are no errors as such :( Don't know where I am going wrong. The values are shown against the field but the checkboxes remain unchecked.

However, I find this line

[webpanels.children.condition.ChildIssuesPanelVisibilityCondition]Exception when evaluating if child issues panel should be displayed

But I dont think it has anything to do with my code

 

Ok, you'll have to go into quite a bit of debugging now.  I'm not sure what's wrong (unless the code you've not shown us here is somehow blanking out the field data you're trying to put into the change), but I'd check the values of variables on each line until you find out where the nulls/empty data is coming from.

This widget could not be displayed.

I managed to get this working with the below code

ArrayList<LazyLoadedOption> optionsList = new ArrayList<LazyLoadedOption>();

FieldConfig fieldConfig = platRelOnAPIField.getRelevantConfig(issue);
  
OptionsManager optionManager = ComponentAccessor.getOptionsManager();
  
platOptions = optionManager.getOptions(fieldConfig);

for(def i = 0;i<platOptions.size();i++){
    def optVal = platOptions.get(i).getValue();
    if(platOptions.get(i).getValue().equals("custom field value")){
      optionsList.add(platOptions.get(i));
    break;
    }
}

Now I have optionsList which I pass like before to updateValue

platRelOnAPIField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(platRelOnAPIField), optionsList),changeHolder)

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

109 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you