Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to remove values from multiselect checkbox?

Paz Grimberg March 6, 2017

Hi,

I want to write a script post function on sub-task transition to "Done" in order to delete values in a custom field of type multiselect checkbox on its parent.

 

Can you please advise how to remove values from multiselect checkbox custom field?

Thanks!!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Alina Fecheta
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.
March 6, 2017

Hello, 

This should help you set the checkbox field to the new values:

https://answers.atlassian.com/questions/64039

https://answers.atlassian.com/questions/24642640

You can provide a list of options when you call issue.setCustomFieldValue()

Paz Grimberg March 7, 2017

Hi Alina,

do you mean that i need to set a list of existing values but the one i want to remove?

What kind of list do i need to create? list of option id's?

Is there a way to remove a single value from being checked?

Thanks

 

Alina Fecheta
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.
March 7, 2017

Hi, Paz

You can get the list of currently checked values with:

issue.getCustomFiedValue(checkBoxField).

This gives you a list of Option objects.

https://docs.atlassian.com/jira/7.0.7/com/atlassian/jira/issue/customfields/option/Option.html

You can iterate through this list, check the value using the getValue() method and remove the option from the list if you don't want to keep it.

Then you can set the custom field value to the new list.

Check the examples I gave you and I think it will be clearer. They were useful to me for a similar task.

 

Paz Grimberg March 8, 2017

Hi Alina,

Thanks much!

I think my script got better but it still doesn't work and there are no errors, can you please advise?

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option

MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("PP-10")
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def involvedField = customFieldManager.getCustomFieldObjectByName('Involved teams')
def involvedValue = issue.getCustomFieldValue(involvedField)
ArrayList<Option> myList =(ArrayList<Option>) involvedValue
ArrayList<Option> values = new ArrayList<Option>();
for(Option option : myList){
     if(option.getValue() != "B"){
		values.add(option)
    }
    
}
issue.setCustomFieldValue(involvedField,values)
Paz Grimberg March 13, 2017

I just had to add issue.store()

Thanks much Alina smile

Alina Fecheta
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.
March 13, 2017

Hi,Paz

Sorry I couldn't get back to you, I was out of office for a few days with limited Internet access.

Great to hear you got it working! You are very welcome smile

2 votes
Elliott Lemberger February 13, 2019

Is there a way to do this without code?

TAGS
AUG Leaders

Atlassian Community Events