Skip to end of metadata
Go to start of metadata

If you have previously installed the ScriptRunner for Jira Cloud add on and have created Enhanced Search filters using this plugin then you can migrate these filters over to the new Enhanced Search for Jira Cloud plugin by running the steps below for each user who you want to migrate the filters for.

Step-by-step guide

In order to migrate the filters for each user.

  1. Navigate to the Script Console inside of your Jira instance at the URL of <JiraBaseUrl>/plugins/servlet/ac/com.onresolve.jira.groovy.groovyrunner/script-console?s=com.onresolve.jira.groovy.groovyrunner__script-console and run the getUsersWithFilters script shown below in order to return a list of all users who have filters that you may want to migrate.
  2. Navigate to the Scheduled Jobs page in your Jira Cloud instance which you will find at the URL of <JiraBaseUrl>/plugins/servlet/ac/com.onresolve.jira.groovy.groovyrunner/scheduled-jobs?s=com.onresolve.jira.groovy.groovyrunner__scheduled-jobs
  3. On the screen that is displayed click the Add Scheduled Job button.
  4. On the screen that is displayed copy the code from the migration script shown below and insert it into the code box.
  5. Set the As this User box at the top of the scheduled Job to the user who's enhanced search filters you want to migrate by specifying the key for the user returned by the script in step 1 as you must run the code as this user in order to have correct permissions to migrate the filters.
  6. Click the Run now button in order to migrate the filters for that user.
  7. Wait for the script to complete and check the Logs tab in order to make sure that all filters migrated correctly.
  8. Repeat the steps above for each user that you need to migrate the enhanced search filters for.

Migration Script:

Please note that in the script you will see the line below which is adding a prefix to each filter as it is migrated.

def migratedFilterNamePrefix = "MigrateFromSR_" 

The reason we add this prefix is due to the fact that Jira will not allow a user to have two filters with the same name which means that we must give the filter a unique name as we migrate it.

You may modify this prefix value if you want to use a different value to give the migrated filter a unique name if you wish to use a different prefix value.

    .queryString("query", "[sr-filters].active is true")
Migration Script
def migratedFilterNamePrefix = "MigrateFromSR_"
def getMyselfResponse = get('/rest/api/2/myself')

assert getMyselfResponse.status == 200

def myAccountId = getMyselfResponse.body.accountId

def scriptRunnerFilters = get('/rest/api/2/user/properties/sr-filters')
        .queryString('accountId', myAccountId)

def enhancedSearchFilters = get('/rest/api/2/user/properties/as-filters')
        .queryString('accountId', myAccountId)

// check if property exists
println 'scriptRunnerFilters: ' + scriptRunnerFilters
println 'enhancedSearchFilters: ' + enhancedSearchFilters

if (!scriptRunnerFilters?.value?.filters) {
def enhancedFilters = enhancedSearchFilters?.value?.filters
enhancedFilters = enhancedFilters ?: []

scriptRunnerFilters.value.filters.forEach { elem ->

    println 'Getting SR filter with id: ' +
    def userFilterDetails = get("/rest/api/2/filter/${}")
    println userFilterDetails

    def newFilterDetails = [
            name: migratedFilterNamePrefix+,
            description: userFilterDetails.description,
            favourite: userFilterDetails.favourite
    println "Creating a new user filter with details ${newFilterDetails}"
    def result = post('/rest/api/3/filter')
            .header('Content-Type', 'application/json')

    println "A new user filter was created with id: ${result}"
    def newFilterId =
            id: newFilterId,
            syncDate: elem.syncDate,
            originalFilter: elem.originalFilter,
            lastMigrated: elem.lastMigrated,
            migratedFilter: elem.migratedFilter,
            jqlQuery: elem.jqlQuery

println "Updating EnhancedSearch filters with ${enhancedFilters}"
def migrateFiltersRequest = put('/rest/api/2/user/properties/as-filters')
        .queryString('accountId', myAccountId)
        .header('Content-Type', 'application/json')
        .body([active:, filters: enhancedFilters])