Forums

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

Trigger "Filter Assign Scope" retroactively (Possible workaround for JSDSERVER-8461)

For Readonly Insight Custom Field, "Filter Assign Scope (IQL)" only takes affect for newly created/updated issues as the filter only gets triggered upon a IssueCreated or IssueUpdated events.

As a result, as a Jira/Insight administrator it's difficult to automatically populate the "Readonly Insight Custom Field" values for existing issues until these issues are manually updated.

 

Read more here: JSDSERVER-8461 : Add ability to trigger "Filter Assign Scope" retroactively for existing issues 

As the feature currently doesn't exist, I tried to write a bash script to invoke issue updates.

#!/bin/bash
# small script as a workaround for JSDSERVER-8461 : Add ability to trigger "Filter Assign Scope" retrospectively for existing issues
# Author: Mr. Doubt Everyhim
# Date: 2021-07-12
#
# PREREQUISITES:
# 1. Need to Install JQ: https://stedolan.github.io/jq/download/
# 2. Must have "Labels" added to "Default issue view screen" for all returned issues by JQL
# 3. User must have edit issue permission

admin_user=<USER>
admin_password=<PASSWORD>
jira_server="http://xxxxxxxx:8080/jira"
url_part2="/rest/api/2/search"
url_part3="/rest/api/2/issue"
FILE="search_results.json"


# Remove if exists


if [ -f "$FILE" ]; then
echo "$FILE exists..Renaming the file and continuing..."
mv "$FILE" $(date +%Y-%m-%d_%H-%M-%S)_"$FILE"
else
echo "$FILE does not exist. Continuing...."
fi

# Get matching issues and iterate over all the matching issues. change the c+=<VALUE> to change the "startAt" value:

for (( c=0; c<=20; c+=2 ))
do
curl --fail --silent --show-error ${jira_server}{$url_part2} -u ${admin_user}:${admin_password} -X POST -H 'Content-Type: application/json' --data-raw '{"jql": "project = Insight and cf[10301] is EMPTY", "startAt": '$c', "maxResults": 2, "fields": ["id","key"]}' |jq --compact-output '.issues[] | {id}' >> search_results.json
done

echo "JQL Results are written in ./search_results.json"
echo "Total issues returned: " $(cat $FILE |wc -l)

# Adding Label:
for i in $(cat ./search_results.json | sed 's/[^0-9]*//g'); do
echo "Adding label for Issue ID: " $i
curl ${jira_server}{$url_part3}/$i -u ${admin_user}:${admin_password} -X PUT -H 'Content-Type: application/json' --data-raw '{"update":{"labels":[{"add":"label_to_deleted"}]}}'
done

# Removing Label:
for i in $(cat ./search_results.json | sed 's/[^0-9]*//g'); do
echo "Removing label for Issue ID: " $i
curl ${jira_server}{$url_part3}/$i -u ${admin_user}:${admin_password} -X PUT -H 'Content-Type: application/json' --data-raw '{"update":{"labels":[{"remove":"label_to_deleted"}]}}'
done

echo "Done!"

 

1 comment

David Yu
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.
June 10, 2025

How about using Script Runner to fire an IssueUpdated event (with no email).

This is one less extra step (don't need to do two actions add/remove a label). I've hardcoded a filter-id here but can easily change it to any JQL.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.issue.Issue;
import com.atlassian.event.api.EventPublisher;

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.issueManager

def MAX_LIMIT_PROCESSED = 100

EventPublisher eventPublisher = ComponentAccessor.getComponentOfType(EventPublisher.class);

Issues.search('filter=74000').take(MAX_LIMIT_PROCESSED).each { searchResult ->
    Issue issue = issueManager.getIssueObject(searchResult.key)

    IssueEvent issueEvent = new IssueEvent(issue, null, user, EventType.ISSUE_UPDATED_ID, false);
    eventPublisher.publish(issueEvent);
    log.info("Updated: " + issue.key);

} 

 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events