ScriptRunner's scripted field not showing up in issue navigator

Using Jira 5.2.2 and ScriptRunner 2.1.3

Problem: I have two fields, each containing multiple Jira versions. The standard field: 'Fix Version/s' and a custom field: 'Planned For'. The 'Fix Version/s' field can only contain versions or a subset of the 'Planned For' versions. I'm trying to created my first custom, scripted field: toPort (an unlimited text field) using ScriptRunner. This field will contain a string of the version names that is the difference/delta between the 'Planned For' and 'Fix Version/s' field.

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import org.apache.commons.lang.StringUtils;

def pfNames = new ArrayList();

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
def pfObj     = customFieldManager.getCustomFieldObjectByName('Planned For');
def pfList    = issue.getCustomFieldValue(pfObj);
def fixedList = issue.getFixVersions();
if (pfList != null) {
  pfNames = pfList.name;
  log.warn("<<BW>>-01 " + StringUtils.join(pfNames, ", "));
  if (fixedList != null) {
    flNames = fixedList.name;
    log.warn("<<BW>>-02: " + StringUtils.join(flNames, ", "));
    pfNames.removeAll(flNames);
  }
  log.warn("<<BW>>-03: " + StringUtils.join(pfNames, ", "));
}
return( StringUtils.join(pfNames, ", ") );

While editing this scripted field, I previewed each of the issues individually and the appropriate version names appeared in the preview pane. In the Issue Navigator, the columns were configured to show this new toPort field.

Then entered jql query#1:

The issues, I expected to be displayed, were displayed but the "toPort" column was not displayed. Then "toPort" was added to the jql query(known as query#2):

The issues, I expected to be displayed, were displayed but the "toPort" column was not displayed. Then "toPort" was added to the jql query(known as query#2):

The "toPort" column was now displayed in the Issue Navigator but only issues where "Fix Version/s" value were not null(empty), are displayed. Then I reversed the toPort portion of the query to check for empty. i.e. (known as query#3)

The remaining issues (query#1 - query#2) are not display along with null and non-null toPort values. Have I built in some dependency with the 'Fix Version/s' field or something that is preventing the displaying of the toPort field all the time in the Issue Navigator?

Any assistance would be greatly appreciated.

5 answers

1 accepted

This widget could not be displayed.

Because my script is returning a string, even if it return a null string the "IS EMPTY" operator does not work on it. As well, the "~" contain operator cannot test for a null string as a result, I changed the return string from:

return( StringUtils.join(pfNames, ", ") );

to

def pfRet = StringUtils.join(pfNames, ", ");
if (pfRet) {
  return( pfRet );
} else {
  return( "none" );
}

So now I can test with the JQL syntax:

toPort !~ none

It may not be pretty but it works.

There's a difference between an empty string and null. If you return null, it will work properly. I'm not quite sure what you mean by a "null string".

You should change it to:

return pfNames.join(", ") ?: null

Thanks Jamie. I tried your solution but I still had the same issue with not being able to use the "is [not] empty" operator. But I will get rid of the StringUtils join...Thanks

Strange, I will test that. Don't forget you will need to reindex all issues affected if you change the script though.

The value displayed on the issue will update immediately you change the code. But, and this only applies if you use an indexer, the indexed value will not. It is only updated when the issue is indexed. A global reindex is the easy option. Another option is to use the method Henning suggested below, which will probably be quicker.

This widget could not be displayed.
Henning Tietgens Community Champion Aug 07, 2013

You should try to reindex the project with the new scripted fields. You could use a builtin script from Script Runner for that. After that, try again.

I reindexed the project from the Admin page menu but no difference. I've read numerous answers about the buildin script reindex feature but I don't see it in my 2.1.3 version of ScriptRunner. I noticed it is up to 2.1.9 so I'll upgrade first and then retry.

This widget could not be displayed.

So I upgraded to ScriptRunner 2.1.9 with my existing 5.2.2 Jira and it got a little better but it is still not displaying properly.

As before the scripted field toPort has been added as a column in the Issue Navigator but if the JQL query does not include evaluating the toPort field then the toPort column is not displayed.

project = TBN and status = resolved

Here where it has changed, when I evaluate the toPort field

project = TBN and status = resolved and toPort is not empty

then all the issue that met the "project = TBN and status = resolved" are displayed along the the appropriate toPort value whether set or empty. e.g.

As you can see, it "seems" to be displaying empty and nonempty values of toPort. When I switch the jql to 'and toPort is EMPTY' then no issues are displayed. Hmmm. So I decided to try checking using contains syntax.

So it looks like the 'contains(~)' syntax can be used but when I try to use check for a null string.

Note: I can put other string values in that search and they work. So all my toPort field values are now not empty but I can't check if it is a null string.

So does it go back to Indexing? Is it something different?

I haven't had much luck putting in the appropriate code to index in the above scripted field code.

Any ideas would be muchly appreciated.

This widget could not be displayed.

Just a note - if you don't use the correct tags, ie the one for this plugin, it's unlikely that all the right people are going to see your question.

This widget could not be displayed.

I created a new scripted field, added the code then reindexed the project from the Admin page. Now the "is [not] empty" operator is working. I guess I need a better understanding of when to reindex. In this particular case, I don't need to reindex within the scripted code itself but if I change the code then I should do a project wide reindex from the admin page. Correct?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

216 views 3 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you