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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.