when creating a new issue make certain fields visible based on other fields

Ramez Kaupak August 25, 2023

in my form i ask. 

Is the issue related to specific components or process plans? - customfield_10689

Yes or No.

if Yes. make the following fields visible:

Process Plan Selection - customfield_10687

Work Order Number, Serial Number - customfield_10690

How much time in delays has this issue caused or would have caused?- customfield_10691

 

If No, then keep them invisible. 

 

I have a Script runner for behaviours but i cant figure out how to code it at all.

please help.

2 answers

1 accepted

0 votes
Answer accepted
Joaquin Fernández Morales
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 25, 2023

Hi @Ramez Kaupak 

 

If you are using SR for JIRA Cloud, then you can fit your goal installing Behaviours. You can read more about Behaviours Cloud here: https://docs.adaptavist.com/sr4jc/latest/features/behaviours

 

In the documentation you will be able to see one special function :  

customfield_xxxx.setVisible(false/true).
I hope it helps. 
Ramez Kaupak August 25, 2023

Yeah, i found documentation on it. but i cant change any fields visibility. this particaular field throws an error. but even other fields dont work. even with no errors. 

is my code wrong?image.png

Joaquin Fernández Morales
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 25, 2023
Hi, 
The code could be similar to the next:
const changeField = getChangeField()
const pendingCF = getFieldById("customfield_10687")
// hidden the field by default  
pendingCF.setVisible(false)

if (changeField.getName() == "TheChangedCustomFieldName"){
if (changeField.getValue().value.toString() == "TheChangedCustomFieldValue")
pendingCF.setVisible(true)
}
Please, change in the previous code the : TheChangedCustomFieldName and TheChangedCustomFieldValue by yours. 
I hope it helps.

Captura de pantalla 2023-08-25 a las 13.39.38.png

Like Ramez Kaupak likes this
Joaquin Fernández Morales
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 25, 2023

Hi, 

Please, if my last response help you and you like it, could you accept my response ? 

Regards, 

Ramez Kaupak August 25, 2023

This was a great help as it partially works. 

for my multiselect field i get an error. (screen shot attached). i went around it by using another custom field and it works. so something about the multiselect field is not right.

image.png

Ramez Kaupak August 25, 2023

Second issue. (skipping the problem with my custom field from my previous reply).

The field that needs to be visible/invisible now completely disapears when i change any field. and i cant bring it back. 

Now, i am making a "title" field disappear based on the question. but like i said. it goes missing when i change any field in issue creation form.

Thank you!


image.png

0 votes
Mathew Rypstra
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 25, 2023

So create a new behaviour, set it to the specific project and issue type, it will need to be a server side script triggered when the form loads.

We had script runner removed so cant test for you and you should test outside your production environment. 

I did ask Chat GPT to clean my code as i always use to do.

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def processPlanField = customFieldManager.getCustomFieldObjectByName("Process Plan Selection")
def workOrderField = customFieldManager.getCustomFieldObjectByName("Work Order Number, Serial Number")
def delayField = customFieldManager.getCustomFieldObjectByName("How much time in delays has this issue caused or would have caused?")

def specificComponentsField = getFieldById("customfield_10689")
def processPlanSelectionField = getFieldById("customfield_10687")
def workOrderSerialField = getFieldById("customfield_10690")
def delayTimeField = getFieldById("customfield_10691")

def isRelatedToSpecificComponents = specificComponentsField.getValue() == "Yes"

processPlanSelectionField.setHidden(!isRelatedToSpecificComponents)
workOrderSerialField.setHidden(!isRelatedToSpecificComponents)
delayTimeField.setHidden(!isRelatedToSpecificComponents)

if (!isRelatedToSpecificComponents) {
processPlanSelectionField.setFormValue(null)
workOrderSerialField.setFormValue(null)
delayTimeField.setFormValue(null)
}


if (isRelatedToSpecificComponents) {
processPlanField.setHidden(true)
workOrderField.setHidden(true)
delayField.setHidden(true)
} else {
processPlanField.setHidden(false)
workOrderField.setHidden(false)
delayField.setHidden(false)
}
Ramez Kaupak August 25, 2023

I tried with ChatGPT. no luck. seems its using wrong language

image.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events