Forums

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

The Text field should be empty when I select another options in the Select list(single choice)

Kumar
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.
October 22, 2018

Hi Team,

Recently I have resolved a task that i have by using the script runner plugin Behavior .

when we select an "Ticket System" and "Other" option in Select List(single choice) a Text field have to appear this is the task that i have resolved here is the link please  refer : https://community.atlassian.com/t5/Jira-discussions/In-Select-List-Single-Choice-customfield-selecting-an-Option/m-p/917813#M5103 

here is the Script that i have used

def otherFaveField = getFieldByName("Name Of TextField") //Give a text field custom field name that you have created 
def faveFruitField = getFieldById(getFieldChanged())

def selectedOption = faveFruitField.getValue() as String
def isOtherSelected = (selectedOption == "Other" || selectedOption == "D") //instead of Other/D You can give another option that you want

otherFaveField.setHidden(! isOtherSelected)
otherFaveField.setRequired(isOtherSelected)

 so every thing is fine now here when I select the Other option the text field is appearing and i'm entering an Text in the Text fields and i'm creating ticket .

after creating ticket when i edit the Selected List(Single Choice) field and selecting another option still the Text Field is showing.

Here i want  when i change the Select Filed the text field should be empty.

please can anyone help in script.

 

Thanks,

Phani 

1 answer

1 accepted

0 votes
Answer accepted
Gundlupet Sreenidhi
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.
October 22, 2018

Hi,

Did you try using the Behavior Plugin - which is now part of ScriptRunner?

Fo to Administration--> Add-Ons --> Behaviors.

Add a new Behavior.

Once your behavior is created, click on the Fields link for that behavior: 

image.png

In the Add field drop-down, select your field you want to act as the trigger (so - you will be selecting the "Ticket System" field)

image.png

 

Once you have added your field, click on the Add Server-side script link to provide the ScriptRunner editor.

Here input your code for what should happen when changes are made to the dropdown. 

 

image.png

 

Modify the customfield IDs per your instance.

if(getFieldById("customfield_11111").getFormValue().toString().equalsIgnoreCase("Other")){
getFieldById("customfield_22222").setHidden(false)
getFieldById("customfield_22222").setRequired(true)
}else{
getFieldById("customfield_22222").setRequired(false)
getFieldById("customfield_22222").setHidden(true)

}

 

I would also recommend create an initialiser.

This basically defines how your screen should appear on initial launch. Here you can set the test box to hidden  and default the value of your select list.

 

Once you are done, make sure to create a mapping. 

A Mapping defines when and where the behavior should be active. (Example: Which project, issue type, etc..)

Kumar
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.
October 22, 2018

Hi @Gundlupet Sreenidhi thanks for your response so here when i select "Other" and "Ticket system" from Select list custom field the text field has to populate 

the above you suggest only "Other" option so I need to add the Ticket system option in that script so how can i add that in the script can you please tell me 

 

Thanks,

Phani

Kumar
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.
October 22, 2018

Hi @Gundlupet Sreenidhi I have tried the script that you have suggested  its not working actually even when i select the Other option the Text Field is not appearing

With My script That i posted earlier  with that  the drop down list when i select  "Ticket system" and "Other" option the Text field is appearing .

But when i edit the ticket and when i change the dropdown list with rest any of the option   the Text i have entered when i select "Other" is still showing 

I want when i change the dropdown list the the text field supposed to disappear  automatically  see the below pics

Thanks,

Phani

text1.PNGtext after edit.PNG

Gundlupet Sreenidhi
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.
October 22, 2018

Hi @Kumar

It is very important that you create the mapping properly. Make sure you select the project and issue type correctly - you will be able to use this setting only on those projects & issue types. (Yes - it is possible to open it to all projects and all issue types)

Also, I guess I forgot to reset the field in my previous thread. 

When the value of your select list is not other, then the value of the text box must be reset.

I have also shown an option to check for multiple values in the select list.

//customfield_11111 is your select list field
//customfield_22222 is your text field

//modify the customfield IDs per your instance.

if(getFieldById("customfield_11111").getFormValue().toString().equalsIgnoreCase("Other")
|| getFieldById("customfield_11111").getFormValue().toString().equalsIgonreCase("Something") ){

getFieldById("customfield_22222").setHidden(false)
getFieldById("customfield_22222").setRequired(true)
}else{
getFieldById("customfield_22222").setFormValue("")
getFieldById("customfield_22222").setRequired(false)
getFieldById("customfield_22222").setHidden(true)

}
Kumar
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.
October 22, 2018

Hi @Gundlupet Sreenidhi  I have tried as you suggested and the I have mapped to single project and all issue types.

I have created field i gave the name and i clicked on Field-->Guide Workflow i select the project work flow---->add filed i selected the drop down custom field which i have--->add script that you have shared i the script after the " || " i got an error whole line 

I have change the Id's of custom filed and agter that I have mapped to particular project an all issue types 

still its not working the text filed is showing default foe all options  below the script that i have modified as you suggested 

 

//customfield_10026 is your select list field
//customfield_10864 is your text field

//modify the customfield IDs per your instance.

if(getFieldById("customfield_10026").getFormValue().toString().equalsIgnoreCase("Other")
|| getFieldById("customfield_10026").getFormValue().toString().equalsIgonreCase("Ticket system") ){
getFieldById("customfield_10864").setHidden(false)
getFieldById("customfield_10864").setRequired(true)
}else{
getFieldById("customfield_10864").setFormValue("")
getFieldById("customfield_10864").setRequired(false)
getFieldById("customfield_10864").setHidden(true)

}

can you please take a look and let me know please

 and please take look that pics that i attached Source 1.PNGSource 2.PNGsource 3.PNGthe Text filed should appear only when i select Ticket system and other option so if i gave any text in text filed even after when i edit the source to email option the text is still showing 

 

sorry for repeating same thing i just want to make sure that you got my point that's it 

 

Thanks,

Phani

Gundlupet Sreenidhi
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.
October 22, 2018

Phani, 

I understand what you are saying. I implemented the same and here is what I have.

(Small change to the code)

 

//customfield_12003 - Data Change Exception
//customfield_12004 - Other Description
if(getFieldById("customfield_12003").getValue().equals("Other")){
getFieldById("customfield_12004").setHidden(false)
getFieldById("customfield_12004").setRequired(true)
}else{
getFieldById("customfield_12004").setFormValue(null)
getFieldById("customfield_12004").setRequired(false)
getFieldById("customfield_12004").setHidden(true)
}

 

Access this link to see how the above code works: https://www.youtube.com/watch?v=o2st9pGV3BE

Gundlupet Sreenidhi
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.
October 22, 2018

The following is for checking against different values:

If value is "something" or "other", then the text box will show, else it will not show.

//customfield_12003 - Data Change Exception
//customfield_12004 - Other Description
if(getFieldById("customfield_12003").getValue().equals("Other")
|| getFieldById("customfield_12003").getValue().equals("Something")){
getFieldById("customfield_12004").setHidden(false)
getFieldById("customfield_12004").setRequired(true)
}else{
getFieldById("customfield_12004").setFormValue(null)
getFieldById("customfield_12004").setRequired(false)
getFieldById("customfield_12004").setHidden(true)
}
Kumar
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.
October 22, 2018

Hi @Gundlupet Sreenidhi now its working great and after creating ticket also when i changed source with other option the text field is disappeared with text 

This is small behavior that i have added 

//customfield_12003 - Data Change Exception
//customfield_12004 - Other Description
if(getFieldById("customfield_12003").getValue().equals("D")
|| getFieldById("customfield_12003").getValue().equals("Other")){
getFieldById("customfield_12004").setHidden(false)
getFieldById("customfield_12004").setRequired(true)
}else{
getFieldById("customfield_12004").setFormValue(null)
getFieldById("customfield_12004").setRequired(false)
getFieldById("customfield_12004").setHidden(true)
}

 thanks for your help  @Gundlupet Sreenidhi

Thanks,

Phani

Kumar
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.
October 22, 2018

Hi @Gundlupet Sreenidhi  I have raised and another issue can you please look it once here is the link that i have posted new issue 

https://community.atlassian.com/t5/Jira-questions/I-want-to-restrict-to-edit-the-quot-Summary-quot-and-quot/qaq-p/920970#U921274

 

Thanks,

Phani

Gundlupet Sreenidhi
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.
October 22, 2018

Suggest an answer

Log in or Sign up to answer