How to remove values from multiselect checkbox?

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!!

1 answer

1 accepted

0 votes
Accepted answer

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()

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

 

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.

 

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)

I just had to add issue.store()

Thanks much Alina smile

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published 2 hours ago in Agile

How Scrum works? It starts with training and education

To answer “How scrum works,” most of the teams I've worked with first addressed the question: “where to start?”  That question applies to both implementation and improvements on the Scrum framew...

28 views 1 2
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