Forums

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

Show/Hide Custom Fields based on the value of Priority (System Field) in Edit Issue Screen

Alvin
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.
September 27, 2018

Hi Community, is it possible to show/hide custom fields on edit issue screen based on value  of System Field?

Scenario is when an agent wants to edit Priority Field , if he/she chooses Priority 1, related custom fields will be shown for Priority 1 in Edit Issue Screen, if Priority 2, related custom fields for Priority 2 will be shown in Edit Issue Screen .

Is it achievable on Behavior? or in Script Listener? or Validator? Thanks

Below is my code on behavior server-side script Priority(system field) , it does not follow the condition

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def customField = getFieldById("customfield_10802")
def priority = getFieldByName("Priority")

if(priority.getValue() as String == ("Priority 1") || ("Priority 2")) {
log.debug(priority)
customField.setFormValue(null)
customField.setRequired(true)

} else {

if(priority.getValue() as String == ("Priority 3") || ("Priority 4"))
log.debug(priority)

customField.setHidden(false)
customField.setRequired(false)
}

 

Thank you!

4 answers

1 vote
Santhosh ESS
Contributor
April 7, 2020

Hi,

It is not working for priority field. Please help me:

I am using the below code:

 

if(field1.getValue() == "P1" || field1.getValue() == "P2")
{
field2.setHidden(false)
field2.setRequired(true)
}
0 votes
Alvin
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.
September 27, 2018
0 votes
Alvin
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.
September 27, 2018
0 votes
Daniel Deng
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.
September 27, 2018

Hi Alvin 

Here is sample code using Behavior,

 

def priority = getFieldByName("Priority")

def customfield1 = getFieldByName("Name of custom field1")

def customfield2 = getFieldByName("Name of custom field2")

 

 

if (priority.getValue() == 1)

   customfield1.setHidden(false)

    customfield2.setHidden(true)   

}

if (priority.getValue() == 2)

   customfield1.setHidden(true)

    customfield2.setHidden(false)   

}

Alvin
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.
September 27, 2018

Hi @Daniel Deng, thank you for the quick turn-around. will try this then. will give you feedback. thanks!

Alvin
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.
September 27, 2018

It does not do the condition on Edit Issue Screen

Daniel Deng
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.
September 27, 2018

Would you mind to share your code and how did you set the behavior? Did you map the behavior to your project?

Alvin
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.
September 27, 2018

I did used your code and mapped the behavior to project, also, I add Priority and added your code to server-side script

Daniel Deng
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.
September 27, 2018

Tried it from my side, added "" like priority.getValue() == "1", and it works

Alvin
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.
September 27, 2018

Hi @Daniel Deng, I have my custom value on Priority, it does not work, it does not follow the condition in else statement. is this working on edit screen?

Suggest an answer

Log in or Sign up to answer