How to show a new field based on another custom field value?

Ankit Jaiswal February 9, 2022

I have a use case.

There is a custom field as Change Result (with values "successful with errors" and "Failed" )

If the value in this field is "Failed"

Then I want to show a new field below this field as "Reason for failure" as a text field.

1 answer

1 accepted

2 votes
Answer accepted
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

@Ankit Jaiswal 

Scriptrunner behaviours!!

Here's a guide

https://scriptrunner.adaptavist.com/5.6.8/jira/behaviours-overview.html

Thanks,

Pramodh

Ankit Jaiswal February 9, 2022

@Pramodh M 

I am new to scriptrunner. Can you send me the script for this use case.

I just want to put a condition on this new field "Reason for Failure" 

The condition will be if the "Change Result" value is "Successful with errors" then this new field will be hidden.

Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

@Ankit Jaiswal 

Here's an example

def change_result = getFieldById(getFieldChanged()).getValue().toString()
if ( change_result == "Failed") {
getFieldById("customfield_10301").setHidden(false);
getFieldById("customfield_10301").setRequired(true);
}
else {
getFieldById("customfield_10301").setHidden(true);
getFieldById("custom field_10301").setRequired(false);
}

"customfield_10301" id is the id of the "Reason for failure" text field

Replace only the ID

You can get that when you edit the custom field, it will be visible in the URL

Let me know if you have any queries

Thanks,
Pramodh

Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 10, 2022

Hi @Ankit Jaiswal 

Let me know if you have tried this script and whether it's working?

Like Gerasimos Kardaras likes this
Gerasimos Kardaras May 20, 2022

@Pramodh M 

In the behaviours you need to add the field that you would like to hide/show or the field that the code is based on?

Suggest an answer

Log in or Sign up to answer