Forums

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

How to check Profiled value in script runner behaviour

nallu August 7, 2019

Hi, 

I want to write a script runner behaviour script based on the Profield value. Can someone please tell me how to get the field value. Based on the value, i will set another field to Hidden.

thanks in advance!! 

I have tried as i do for normal custom field. But It didn't work out. Please find my code below,

 

import com.atlassian.jira.project.Project

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;

//Defining Audience custom field object
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def audienceField = customFieldManager.getCustomFieldObject("customfield_16603");

Project project = getIssueContext().getProjectObject()
String projectCategory = project.getProjectCategory().getName() as String

String projectKey = project.getKey()

def feature_link_field = getFieldById('customfield_15727') // Defining an object for Feature Link issue

if(underlyingIssue.getCustomFieldValue(audienceField).toString() == 'Development') {
feature_link_field.setHidden(false);
}

2 answers

0 votes
Roman Kersky
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.
August 7, 2019

HI.


 

import com.atlassian.jira.component.ComponentAccessor;
def audienceField = getFieldById("customfield_16603")

if(audienceField.getValue().toString() == 'Development')
     getFieldById("customfield_15727").setHidden(false)
nallu August 7, 2019

Hi @Roman Kersky , I also updated the code as you have suggested here.. But it returns null.. 

Screen Shot 2019-08-07 at 3.29.37 PM.png

0 votes
Tansu Akdeniz
Community Champion
August 7, 2019

Hi @nallu ,

As I understand from your code, you get audienceField from the issue (not in screen pop-up),

  •  If it's value is "Development", than you make"feature_link_field" visible in pop-up screen. 

Why do you need projectKey and category? You didn't use these variables. Also, if you face an issue with this script, you can use field.setHelpText() to see variables. Or put log.error() to some lines and check atlassian-jira.log file.

Regards

nallu August 7, 2019

Hi @Tansu Akdeniz , Thanks for the response. 

Yes. What you understand is correct. I was just playing with project key and category. Actual use case is, I need to display the 'Feature_link_field' if audience == 'Development'. I want have this behaviour in all the screens (including create screen).

Note: Audience is Profield which is mapped with any screens. 

Here is my code,

import com.atlassian.jira.project.Project

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;

//Defining Audience custom field object
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def audienceField = customFieldManager.getCustomFieldObject("customfield_16603");

//def audienceValue = underlyingIssue.getCustomFieldValue(audienceField).toString();

def feature_link_field = getFieldById('customfield_15727') // Defining an object for Feature Link issue

feature_link_field.setHelpText("Hi Test!!");

/**
if(audienceValue == 'Development') {
feature_link_field.setHidden(false);
}
**/

 

As you have suggested, I have tried using the setHelpText. The help text display correctly when the below line is commented. 

//def audienceValue = underlyingIssue.getCustomFieldValue(audienceField).toString();

 

When it is Uncommented, the help text fails to display. so i think, there is something wrong with that line. 

Please help..

Tansu Akdeniz
Community Champion
August 7, 2019

Hi @nallu ,

Is that Audience field stored in an issue? If not, following method returns null.

Please check;

String audienceValue = underlyingIssue.getCustomFieldValue(audienceField);

feature_link_field.setHelpText("Audience Value: " +audienceValue);

Do you mean Profields for Jira add-on by profields (Audience)? If yes, you need to search for a Java method to get this value. Because it is a Project based customfield.

nallu August 7, 2019

It is stored in project level only. But the value will also get stored for individual issues in that project as well. I am able to get the data in script field. 

And, Yes it is a add-on Profileds. 

 

When I add this line, it not at all displaying the help text. 

String audienceValue = underlyingIssue.getCustomFieldValue(audienceField);

Suggest an answer

Log in or Sign up to answer