Filters and searches with issueFunction are not working as expected in Jira
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Adaptavist's ScriptRunner app provides a JQL function called issueFunction and it may not bring as many results as expected.
This may be observed after some data or configuration import through Jira native tools or 3rd party apps such as Configuration Manager, Project Configurator, etc.
Environment
Any version of Jira 7.x and 8.x.
Any version of ScriptRunner installed.
Diagnosis
Searches using issueFunction are bringing less issues than what's expected.
Confirm if there are any Field Configurations with the issueFunction field hidden:
1
2
3
select * from fieldlayoutitem
where fieldidentifier = concat('customfield_', (select id from customfield where cfname = 'issueFunction'))
and ishidden = 'true';
If the above query returns any rows, it means the locked field issueFunction created by ScriptRunner has been removed from some Field Configurations. This prevents the function from working on the projects and issuetypes it's been removed from.
Cause
Jira doesn't allow removing locked fields from Field Configurations in the UI, yet this scenario is possible if an Admin has manually unlocked the field sometime or some config or restore procedure with a 3rd party app has ever failed (it may have succeeded in further attempts, but the Field Configs were already tampered with).
Solution
ScriptRunner console solution
When ScriptRunner's enabled, it creates the issueFunction field if it doesn't exist, so we may remove it through ScriptRunner's own console then disable/enable the app:
Open ScriptRunner's console and run the script below.
Disable then re-enable ScriptRunner in Jira's Manage Apps screen.
Perform a full lock & reindex in one of the DC nodes (or a background reindex only if single-node).
ScriptRunner remove issueField script
1
2
3
4
5
6
7
8
9
10
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)
Note that removing the field and disabling/enabling ScriptRunner will recreate the issueField with another custom field Id. If somehow you make use of this field Id anywhere (you shouldn't, though), heed to updating it's references.
Database solution
Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
You may re-enable the locked fields in Jira following these steps:
Stop Jira (on all nodes).
Backup the database (to restore if needed to rollback/backout).
Run the update command below and commit it.
Start Jira one node at a time.
Start a full lock & reindex in one of the nodes. If single-node, you may start a background reindex.
Update command to fix all locked fields that've been hidden/removed from Field Configs:
Postgres example
1
2
3
4
5
update fieldlayoutitem set ishidden = 'false'
where fieldidentifier in (
select fli.fieldidentifier from fieldlayoutitem fli
where fli.fieldidentifier = concat('customfield_', (select id from customfield where cfname = 'issueFunction'))
and fli.ishidden = 'true');
MySQL example
1
2
3
4
5
update fieldlayoutitem as flia
inner join fieldlayoutitem as flib on flia.id = flib.id
set flia.ishidden = 'false'
where flib.ishidden = 'true'
and flib.fieldidentifier = concat('customfield_', (select id from customfield where cfname = 'issueFunction'));
The examples above are for Postgres and MySQL. You may adjust them to the specific syntax of your database if the Postgres example doesn't work.
Wider solution
Actually, no locked field in Jira should be hidden/removed in any Field Configuration, so you may run the following update instead of the ones in the "Database solution" above:
Postgres example
1
2
3
4
5
6
7
update fieldlayoutitem set ishidden = 'false'
where fieldidentifier in (
select fli.fieldidentifier from fieldlayoutitem fli
join managedconfigurationitem mci on mci.item_id = fli.fieldidentifier
where mci.item_type = 'CUSTOM_FIELD'
and mci.access_level = 'LOCKED'
and fli.ishidden = 'true');
MySQL example
1
2
3
4
5
6
update fieldlayoutitem as flia
inner join fieldlayoutitem as flib on flia.id = flib.id
inner join managedconfigurationitem mcib on mcib.item_id = flib.fieldidentifier
set flia.ishidden = 'false'
where flib.ishidden = 'true'
and mcib.item_type = 'CUSTOM_FIELD' and mcib.access_level = 'LOCKED';
Was this helpful?