Troubleshooting JQL Functions
Function Name Clashes
Some other plugins may provide functions with the same name as those provided by ScriptRunner, eg hasAttachments
. For functions like these, no other name would make a great deal of sense, so this is not surprising.
The rules for when that happens are explained in JRA-24219, i.e. the plugin key that is first alphabetically will "win". As the other plugin is generally "JQL Tricks", whose key is before ScriptRunner's, functions from that plugin are normally registered over ScriptRunner's.
If you want to use both plugins, go to "Manage Plugins", expand the modules for either plugin and selectively enable or disable the JQL function modules for those functions. For example, in ScriptRunner, the module providing hasAttachment is displayed as:
Indexing Problems
Most ScriptRunner JQL functions work by using a custom field called issueFunction
. This field is managed (locked), so it can't be on any screen, and has a global context.
The Lucene indexers associated with the custom field are responsible for maintaining the index data that allows the ScriptRunner JQL functions to work.
In extremely rare circumstances, for reasons yet to be determined, Jira decides that the `issueFunction` field is not in scope for particular issues despite its global scope. This can result in problems with the affected issues either incorrectly appearing in the results of queries (such as linkedIssuesOf
etc), or being missed from those results.
Verify the Problem
You can verify if Jira considers `issueFunction` out of scope by running the following script. Update the script below to reference an existing issue you suspect is not being reindexed. If this script returns true
this is not the problem. If it returns false
follow the instructions in the workaround below.
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def fields = customFieldManager.getCustomFieldObjectsByName('issueFunction')
assert fields.size() == 1
def issueFunction = fields.first()
def issue = issueManager.getIssueObject('ABC-1') // CHANGE THIS ISSUE KEY
issueFunction.isInScope(issue.projectId, issue.issueTypeId)
Variation
There is a variation of this problem where the custom field becomes hidden in a particular configuration scheme. To detect this issue, run the script below. If this script has any result, other than No problems
, contact support.
import com.atlassian.jira.component.ComponentAccessor
def field = ComponentAccessor.customFieldManager.getCustomFieldObjects().find { it.name == 'issueFunction' }
assert field
ComponentAccessor.fieldLayoutManager.getEditableFieldLayouts().findAll {
it.getFieldLayoutItem(field.id).isHidden()
}*.name ?: 'No problems'
Workaround
At any stage feel free to contact support.
It appears that the issue in recognising `issueFunction` as a global custom field is due to a referential integrity problem in Jira's database, which could be caused by another plugin, or perhaps direct database edits.
The workaround is to delete the issueFunction
field, and disable then enable the ScriptRunner plugin. When the plugin starts it will recreate this field.
Deleting and recreating the field will not cause any problems, other than you should do a full re-index after this process, so that we can index any issues that have been missed during the time this wasn't working correctly.
As the field is "managed" you need to execute the following code in the Script Console to delete it:
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager
def fields = customFieldManager.getCustomFieldObjectsByName('issueFunction')
assert fields.size() == 1
def field = fields.first()
customFieldManager.removeCustomField(field)
After running the script:
- Navigate to Admin → Manage Apps.
- Disable ScriptRunner.
- Once disabled, enable it again. (You could also restart Jira instead).
- Re-run the verification script. This should now be returning
true
where previously it returnedfalse
.
JQL functions should now be working correctly for issues created or edited after this point.
Do a full re-index of Jira (foreground or background) at a time convenient to you to ensure all issues are correctly indexed.
If you know which projects are affected, you can re-index specific projects rather than the entire Jira instance.