It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Display web panel based on custom field value

tonyrath I'm New Here Sep 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

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 Sep 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

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
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

344 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you