Need help to setCustomFieldValue for a Select List type

mehala n
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.
August 27, 2013

I have a list of Select List type custom fields in which I need to set "Not Required" as default Value while doing "Generate CheckList" step in workflow.

myIssue.setCustomFieldValue(cf, "Not required") -cf is a Select List type custom field.

This kind of code upto JIRA 4.2 version.Now I get ClassCastException.

Can anyone help to setCustomField Value for Select List Type.

4 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 27, 2013

Select lists store "option" objects, not "strings". You need to find the "Not Required" option in the list of options, and pass that in instead of the string, or create the option from the string as you go.

mehala n
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.
August 27, 2013

Thanks Nic.It works after I pass it as Option instead of String.

Now I need to itertate thruough a set of Custom Fields and setCustomFieldValue.It could be a combination fo text,select list etc.

How to check the type of Custom Field and do setCustomFieldValue accordingly.

Can you please give some examples?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 29, 2013

Sorry, I missed the comment. I don't know if there's an approved way to do it, but I simply get the class name of the object I get back and execute a set of "if" to handle each possible type. Feels clumsy to me, but I've never had time to look for something better.

JamieA
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.
September 4, 2013

If the custom fields expect different values I don't see any alternative...

RambanamP
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.
September 5, 2013

you have to try something like this

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.crowd.embedded.api.User

 
MutableIssue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField customField = customFieldManager.getCustomFieldObjectByName("Overall Impact")

Option fieldVal =(Option) issue.getCustomFieldValue(customField)
   if((fieldVal.getValue()).equals("Low")){
  
   }

1 vote
JamieA
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.
September 5, 2013

cfValues['Overall Impact'].value == 'LOW'

mehala n
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.
September 12, 2013

cfValues['Overall Impact'] == 'LOW' .

This works good now.

Thanks

0 votes
mehala n
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.
September 8, 2013

Jamie ,

cfValues['Overall Impact'].value == 'LOW' also didnt work out.

Nic,

It is simple scripted validator.Iam trying to chk if Over All Impact has been set to LOW,then validating it for some more conditions.

Thanks

JamieA
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.
September 8, 2013

it does work. Go to Admin -> Condition Tester and do:

assert cfValues['Overall Impact'].value == 'LOW'

then paste back here the output in red as a comment. Choose an issue where that should evaluate to true.

0 votes
mehala n
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.
September 5, 2013

Hi Nic,

cfValues['Overall Impact'] == 'LOW'

I couldnt see any issue in this line.But Workflow is not recognizing this value though 'Overall Impact' is set as LOW.Please help (JIRA version is 5.2)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2013

I'm afraid I don't understand that. I don't know what you're trying to do, or why you mention workflow when you're looking at a field option.

Could you tell us where you're trying to use thi?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events