It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to remove values from multiselect checkbox?

Paz Grimberg Mar 06, 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

0 votes
Answer accepted
Alina Fecheta Mar 06, 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 Mar 07, 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 Mar 07, 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 Mar 08, 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 Mar 13, 2017

I just had to add issue.store()

Thanks much Alina smile

Alina Fecheta Mar 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

0 votes
Elliott Lemberger Feb 13, 2019

Is there a way to do this without code?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

1,880 views 14 17
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you