Auto populate custom field based on jql query result

David Antebi July 19, 2018

Hi,

I would like to auto populate custom field if an issue match jql query results.
I think to use scripted listener but I don't know how to write the script for it.

Can anyone help me please?

Thanks!

1 answer

0 votes
Neta Elyakim
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.
July 25, 2018

You can use escalation service- https://scriptrunner.adaptavist.com/latest/jira/escalation-service.html

I think it's better for you if you want to do it base on JQL result.

You can Build your cron expression here- 
https://www.freeformatter.com/cron-expression-generator-quartz.html

Just write there you JQL and add this script: (note that you need to change the "My Custom Field" - to your custom field name and "cf value" to the relevant value)

This code relevant for custom field of type string (Text Field)

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'My Custom Field'}
issueInputParameters.addCustomFieldValue(cf.id, 'cf value')

If your field type is select list use this:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Some Select List") // name of CF

def optionsManager = ComponentAccessor.getOptionsManager()

def fieldConfig = customField.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find { it.value == "Yes" } // value of option

issueInputParameters.addCustomFieldValue(customField.id, option.optionId as String)
issueInputParameters.setSkipScreenCheck(true)

Here is an example of an escalation service that run - At 00:00:00am every day and the action is happening as a user how called "admin":

es.PNG

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events