Forums

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

Display web panel based on custom field value

tonyrath
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!
September 13, 2019

I have a web panel created through scriptrunner that I want displayed only if a customfield has been populated with a value.

 

I've been trying to use condition to no avail

 

Tried setting condition in script to :

cfValues['Priority Score'] > 0

But I get a cfValues is undeclared in the code box and regardless of value the web panel doesn't show.

 

How do I properly reference the custom field "priority score" in a condition

 

 

1 answer

1 accepted

0 votes
Answer accepted
Tuncay Senturk _Snapbytes_
Community Champion
September 14, 2019

Hi @tonyrath 

I'm not Script Runner expert, but let me try to help.

Where do you find or set cfValues?

I think you should write a script to get the custom field value and return true if the field has value as below. 

Please be aware that I did not try the code, I just write it here.


import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
CustomField cf = customFieldManager.getCustomFieldObjectByName('Priority Score')
return null != issue.getCustomFieldValue(cf)
tonyrath
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!
September 16, 2019

Thanks  Tuncay, that got me on the right path

This is what ended up working :

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10504")
def cFieldValue = issue.getCustomFieldValue(cField)

cFieldValue != null

Tuncay Senturk _Snapbytes_
Community Champion
September 16, 2019

I'm glad to hear that.

Please accept the answer so that other community members who has similar issues would see the correct path.

Cheers

Suggest an answer

Log in or Sign up to answer