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 show multiple custom fields bases on selecting a value from multi-choice list?

i have multi-choice list of values a,b,c,d,e,

i have a custom text fields of a1,b1.c1,d1,e1

when i choose value  "a" from the multi-choice list it show a text field of a1

when i choose  value "b" from multi-choice list it should show custom filed b1 in the same way for all the values in the multi-choice list. please help me out? i tried for showing one text filed for am not able to figure out how to show multiple text fields bases on the selection of value of multi-choice list? please help me out with a snippet

2 answers

1 accepted

0 votes
Answer accepted
Antoine Berry Community Leader Apr 16, 2019

Hi @rakesh rocckz ,

You could try 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript


@BaseScript FieldBehaviours fieldBehaviours

int multiSelectListId = 10100
int a1id = 10101
int b1id = 10102
int c1id = 10103
int d1id = 10104
int e1id = 10105

def multiSelectList = getFieldById("customfield_" + multiSelectListId)
def a1 = getFieldById("customfield_" + a1id)
def b1 = getFieldById("customfield_" + b1id)
def c1 = getFieldById("customfield_" + c1id)
def d1 = getFieldById("customfield_" + d1id)
def e1 = getFieldById("customfield_" + e1id)

def multiSelectListValue = multiSelectList.getValue()

a1.setHidden(true)
b1.setHidden(true)
c1.setHidden(true)
d1.setHidden(true)
e1.setHidden(true)

if (multiSelectListValue.contains("a1")){
a1.setHidden(false)
}
if (multiSelectListValue.contains("b1")){
b1.setHidden(false)
}
if (multiSelectListValue.contains("c1")){
c1.setHidden(false)
}
if (multiSelectListValue.contains("d1")){
d1.setHidden(false)
}
if (multiSelectListValue.contains("e1")){
e1.setHidden(false)
}

Of course replace the custom field ids with the correct ones.

Antoine

@Antoine Berry it worked. is it possible can i map the customfield data and value of multi-select choice value? or store all these  data both the multi-select choice value and the customfield value in another customfield?i mean storing all these values in the one customfield so that i need to call just one customfield rather then calling all custom fields?

Antoine Berry Community Leader Apr 17, 2019

Hi,

Depending on what you need, you can achieve that with behaviours, using the 

cf.setFormValue(...

method. Otherwise I guess you can use a scripted field or a script post function.

Antoine

@Antoine Berry rather then mentioning custom field number each time to hide and show is there any way  can i create the custom fields from script? i mean right now i have values a,1b1,c1,d1,e1 but in future if value f1 comes again i need to change the script and create a customfield manually its a lot of manual process.is there a way can we create a new custom fields whenever a new  value comes in the multi-choice list?? basically i am trying to show text field for every selection of value from multi-choice list. 

 

My Idea: is there a way we can append these values in another customfield .

for example: if i select "a1" it should show a text field and i will enter the text then next if i select another value the text what i enter for the value "a1" should be erased and store in an another custom field so then if i select b1 it should show the same text field again then i will enter the text then it should store this value where a1 value was stored  in the samey way for all whenever we select a new value from the multi-choice list it shouls a empty text field then we will enter the data and it should store in an another custom fields so that i can just call this customfield value and get all the data what i enter for all the values.

 

Your code helped me alot, but i need to manually create the customfields everytime when a new values comes in the multi-choice list. please help me out a way we can create a new customfield from the script itself?

Antoine Berry Community Leader Apr 18, 2019

Hi @rakesh rocckz ,

I have never created a custom field in a script. However this is possible, this is the solution given by Thanos Batagiannis here :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def newCustomField = customFieldManager.createCustomField("name", "description", CustomFieldType fieldType, CustomFieldSearcher customFieldSearcher, List<JiraContextNode> contexts, List<IssueType> issueTypes)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.GlobalIssueContext
import com.atlassian.jira.issue.context.JiraContextNode
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.issuetype.IssueType
createCF()
CustomField createCF() {
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def constantsManager = ComponentAccessor.getConstantsManager()
def taxtAreaType = customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:textarea")
def textAreaSearcher = customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:textsearcher")

//set global context
List<JiraContextNode> contexts = new ArrayList<JiraContextNode>()
contexts.add(GlobalIssueContext.getInstance())

def bugIssueType = constantsManager.allIssueTypeObjects.find {it.name == "Bug"}
List<IssueType> issueTypes = new ArrayList<IssueType>()
issueTypes.add(bugIssueType)
return customFieldManager.createCustomField("Text-Area CF",
"A newly created text area CF for testing",
taxtAreaType,
textAreaSearcher,
contexts,
issueTypes
)
}

You can check the javadoc for more details. 

Antoine

@Antoine Berry so in a simple way, it should show a text field for every selection of the multi-choice list so the data what we enter in the text field should append or store in a another custom field so all the data what we enter each time when we select a value it should store in another custom field, in this way whenever a new value comes in the multi-choice  list we dont need to create a new custom field.in the end, we can just call that one custom field value where all the data is stored and we can use it.please help me how to append the data in another custom field this is the real problem because of this issue itself the whole problem comes into the picture.I really appreciate for helping me out but my problem is to append the data in another custom field.

Antoine Berry Community Leader Apr 19, 2019

Hi @rakesh rocckz ,

You probably want to do this in a postfunction or a script listener instead of a behaviours. Here is an example : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue

def customFieldManager = ComponentAccessor.getCustomFieldManager()

int a1id = 10101
int a2id = 10102
int fieldToAppendId = 10200

def a1 = customFieldManager.getCustomFieldObject(a1id)
def a2 = customFieldManager.getCustomFieldObject(a2id)
def fieldToAppend = customFieldManager.getCustomFieldObject(fieldToAppendId)

String a1Value = issue.getCustomFieldValue(a1)
String a2Value = issue.getCustomFieldValue(a2)
String fieldToAppendValue = issue.getCustomFieldValue(fieldToAppend)

fieldToAppend.updateValue(null, issue, new ModifiedValue(fieldToAppendValue, fieldToAppendValue + " a1 : " + a1Value + "a2 + " + a2Value), new DefaultIssueChangeHolder())

 assuming a1, a2 and fieldToAppend are Text Custom Fields.

Antoine

@Antoine Berry no thats not my question. i want to show the same textfield everytime a value is selected from multi-choice list so everytime when i enter the text in that textfield itshould store that data in another customfield. 

for example, there are 3values apple,car,dog in the multi-choice list. if i select the apple it should show a textfield then i will enter the text for example  "fruit" then again if i choose another value from the multi-choice list  "car" it should show the same textfield empty so that i can enter the text for "car" as vehcile in the sameway for every value it should show the same textfield. so all the text what i enter fruit,vehciles ..etc should store together in an another customfield. in this way whenever  a new value comes in the multi-choice list we dont need to create a new customfield all the text what i enter for everyvalue will store in that customfield. please please help me out this is the real problem i havent find a solution any where. i just want to append the data of the textfield and for every value it should show the same textfield.i really appreciate for responding

The below code works great it does the job but for example, when I select a value from the list it shows a text field which is good  and then i will enter the text in the textfield  but when I cancel the value it hides a text field which is good but after canceling when I create the issue the cancelled text field  still shows in the issue after creating. is there anyway can hide that?  @Antoine Berry 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript


@BaseScript FieldBehaviours fieldBehaviours

int multiSelectListId = 10100
int a1id = 10101
int b1id = 10102
int c1id = 10103
int d1id = 10104
int e1id = 10105

def multiSelectList = getFieldById("customfield_" + multiSelectListId)
def a1 = getFieldById("customfield_" + a1id)
def b1 = getFieldById("customfield_" + b1id)
def c1 = getFieldById("customfield_" + c1id)
def d1 = getFieldById("customfield_" + d1id)
def e1 = getFieldById("customfield_" + e1id)

def multiSelectListValue = multiSelectList.getValue()

a1.setHidden(true)
b1.setHidden(true)
c1.setHidden(true)
d1.setHidden(true)
e1.setHidden(true)

if (multiSelectListValue.contains("a1")){
a1.setHidden(false)
}
if (multiSelectListValue.contains("b1")){
b1.setHidden(false)
}
if (multiSelectListValue.contains("c1")){
c1.setHidden(false)
}
if (multiSelectListValue.contains("d1")){
d1.setHidden(false)
}
if (multiSelectListValue.contains("e1")){
e1.setHidden(false)
}

 

Antoine Berry Community Leader Apr 23, 2019

I'm not sure I understand correctly, but maybe this should answer your needs  ?

if (multiSelectListValue.contains("a1")){
a1.setHidden(false)
} else {
a1.setFormValue(null)
}

if (multiSelectListValue.contains("b1")){
b1.setHidden(false)
}
else {
b1.setFormValue(null)
}

if (multiSelectListValue.contains("c1")){
c1.setHidden(false)
}
else {
c1.setFormValue(null)
}

if (multiSelectListValue.contains("d1")){
d1.setHidden(false)
}
else {
d1.setFormValue(null)
}

if (multiSelectListValue.contains("e1")){
e1.setHidden(false)
}
else {
e1.setFormValue(null)
}

i.e. clear the a1 field if a1 is not selected in the multi select list (same for the other fields).

Antoine

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Desk

How do you onboard new employees using Jira Service Desk?

Hello Community 👋, I'm a product manager on JSD.  If you're responsible for onboarding employees, I'd like to speak to you to learn about the range of tasks that are involved in setting up...

356 views 14 3
Join discussion

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