Forums

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

I would like to count the options chosen in multi-select custom field

annag December 17, 2019

Here is the code that I have so far:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
//log.setLevel(Level.DEBUG);

def xMultiSelectPtr = getFieldByName("xx_sfi_apps");
def xMultiSelectVal = xMultiSelectPtr.getValue();
log.info("xMultiSelectVal =====>"+xMultiSelectVal)

//xMultiSelectVal returns something like [1, 3, 6]

// If xMultiSelectVal.size() > 1//{Ask if user meant to choose more than one//}

I am trying to find a way to set the help text if the user chose more than one option.

Any help would be greatly appreciated!!! :)

...AnnaG...

1 answer

1 accepted

0 votes
Answer accepted
Leo
Community Champion
December 17, 2019

Hi @annag,

 I don't have any active script with me, but I'm modifying adaptavist script according to your requirement.  I haven't tried in my system though, this may require minor changes.

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
//log.setLevel(Level.DEBUG);
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScrip FieldBehaviours fieldBehaviours

def xMultiSelectPtr = getFieldByName("xx_sfi_apps");
def xMultiSelectVal = xMultiSelectPtr.getValue();
log.info("xMultiSelectVal =====>"+xMultiSelectVal)

//xMultiSelectVal returns something like [1, 3, 6]

if (xMultiSelectVal.size() > 1){
xMultiSelectPtr.setLabel("Help text here")
xMultiSelectPtr.setDescription("Field Description here")
}

 Here is the page from adaptavist for reference

Hope this gives you some idea

 

BR,

Leo

annag December 18, 2019

Thank you for your response!!! It gives an error on the .size() parameter, which is what I have been running in to. I have tried every option except for the correct one. Lol Here is a screenshot and I would appreciate any suggestion on how to resolve this:

2019-12-18_6-49-45.png

Leo
Community Champion
December 18, 2019

If you modify your getValue() code like below may fix your issue

def xMultiSelectVal = xMultiSelectPtr.getValue() as List

or you can iterate over the object and count them(mostly above one should fix your issue)

 

BR,

Leo 

annag December 18, 2019

You are Awesome!!! It is finally giving me the size. It doesn't show the help text (This is a behaviour in a Create/Update Issue screen). I will play with trying to display some type of message to the user. Basically, I want to call to attention that they chose more than one application and give them a chance to modify their selection. I was hoping for a Are you sure dialog box, but I have not found anything like this. Thanks so much!!!

annag December 18, 2019

Leo, your code worked purrfectly! I just missed seeing the help description. I will work on making it more prominent to the user. For anyone looking for the answer, this is the code that worked:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
//log.setLevel(Level.DEBUG);
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def xMultiSelectPtr = getFieldByName("xx_sfi_apps");
def xMultiSelectVal = xMultiSelectPtr.getValue() as List;

log.info("xMultiSelectVal =====>"+xMultiSelectVal)
log.info("xMultiSelectVal.size ------------->>"+xMultiSelectVal.size())
//xMultiSelectVal returns something like [1, 3, 6]

if (xMultiSelectVal.size() > 1){
log.info("******I am inside the If statement *******")
xMultiSelectPtr.setLabel("Help text here")
xMultiSelectPtr.setDescription("Are you sure you meant to choose multiple applications?????????????")

Thanks again!!!

...AnnaG... 

Like Leo likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events