Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to set field is required based on other field value in drop down selection

Velkuri Balaji June 23, 2023

Hello,

We would like to set "Preliminary Estimate" field is required when we select "Epic Type" field as 'Product Innovation'  (in drop down options, we have other value as Product Improvement).

To achieve this we are trying to use behaviour function and used below script and it's working fine during issue creation level.

const preliminaryEstimateField = getFieldById("customfield_10107");
const epicTypeField = getFieldById("customfield_12161");

if (epicTypeField.getValue().name == "Product Innovation") {
preliminaryEstimateField.setRequired(true);
} else {
preliminaryEstimateField.setRequired(false);
};

However,  While creating issue I can choose 'Epic Type' as 'Product Improvement' so that I can skip Preliminary Estimate Field. After that I can open issue and Change the 'Epic Type' to 'Product Innovation' and here it's not asking to fill 'Preliminary Estimate' Filed as required. but we are expecting it must ask to fill 'Preliminary Estimate' field (during edit issue level also)

The above script is working fine during issue creation level but it's not performing during edit issue level.

Could someone help on this issue.

Note: " We are using Jira Cloud not Jira Server, Behaviour feature is now available for Jira cloud "

 

Thank you

Balaji 

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2024

Hi @Velkuri Balaji

Since you need to set the Product Improvement field to required based on the option selected in the Epic Type field, the approach you are using will not work.

I suggest modifying your code to:-

const changedField = getChangeField();

const isRequired = changedField.getType().toString() == "com.atlassian.jira.plugin.system.customfieldtypes:select"

&& changedField.getName() == "Sample List"

&& changedField.getValue()["value"].toString() == "Option1"

getFieldById("customfield_10046").setRequired(isRequired);

Please note that the sample working code above is not 100% exact to your environment. Hence you will need to make the required modifications.

Below is a screenshot of the configuration:-

image1.png

In the example above, only if Option1 is selected from Sample List will Sample List 2 be set to required. Else if any other option is selected from Sample List, Sample List 2 will not be required.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2024

Hi @Velkuri Balaji

Since your requirement is to set the Preliminary Estimate Field to required based on the option selected in the Epic Type Field, your approach is incorrect.

Instead, you should try something like this:-

const changedField = getChangeField();

const isRequired = changedField.getType().toString() == "com.atlassian.jira.plugin.system.customfieldtypes:select"

&& changedField.getName() == "Sample List"

&& changedField.getValue()["value"].toString() == "Option1"

getFieldById("customfield_10046").setRequired(isRequired);

Please note that the sample working code above is not 100% exact to your requirement. Hence, you will have to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

image1.png

For the sample case above, I am running the test on two single Select Lists, i.e. Sample List and Sample List 2. 

Only if Option1 is selected from Sample List Sample List, 2 will be set to required. If any other option is selected from Sample List, Sample List 2 will not be set to required.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events