ScriptRunner's scripted field not showing up in issue navigator

Brent Webster
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 6, 2013

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

0 votes
Answer accepted
Brent Webster
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 28, 2013

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.

JamieA
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 28, 2013

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

Brent Webster
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 28, 2013

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

JamieA
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 29, 2013

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

JamieA
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 29, 2013

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.

0 votes
Brent Webster
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 29, 2013

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?

0 votes
JamieA
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 16, 2013

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.

0 votes
Brent Webster
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 13, 2013

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.

0 votes
Henning Tietgens
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, 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.

Brent Webster
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, 2013

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.

Suggest an answer

Log in or Sign up to answer