How to set Elements Connect field on existing issues?


Table of Contents


Once an Elements Connect field is configured, it won't just appear on Jira issues, it needs to be set (populated).

To set an Elements Connect field on new issues, there are several possibilities:

But, what about setting the field on existing Jira issue?

Three options are available, the first one depends only on Elements Connect and a Jira functionality, where the other two solutions depends on a 3rd party Apps.

Dependecies

It's important to mention that this KB is to set an Elements Connect field with no dependencies (no reference to $issue in the field configuration).

If the field that needs to be set has a dependency to another field, then, parent field needs to be set separately by using one of the below methods.

By creating a temporary transition

  • Per project, create a new temporary transition that doesn't change the workflow status: from status Any status, to status Itself.





  • This transition could be deleted after the Connect field is set, or it could be hidden by adding a condition on the transition: Condition to hide a transition from the user.
  • Edit the new transition and add our dedicated post function Elements Connect: Set a field value to set the Connect field.
  • Select the Connect field you need to set on the issues.
  • We can add as many fields as needed.
  • Publish the workflow.
  • In Jira issues, run a JQL query that will retrieve the issues where we need to set the Connect field.
  • From Tools, select "Bulk change".





  • Select all the issues, click "Next"
    • (warning) in case of doubt, it could be done on one issue to ensure everything is working as expected, later-on, apply it on remaining issues.
  • Select "Transition Issues" operation, click "Next".
  • Select the created transition, click "Next" till confirming the transition of the issues.
  • The above bulk operation might need to be done several times because it's per status. If the issues are in different statuses, repeat the above.
  • Finally, ensure that the issues were correctly updated.

By configuring an Automation rule

  • From the administration page of Automation for Jira, click on "Create rule".
  • Select the Scheduled trigger.
  • Set the rate on running the rule, 7 minutes for example (the number is not important as the rule will be run manually and for one time only).
  • Set the JQL query that will retrieve the Jira issue where the Connect field is not populated.
  • Click "Save".






  • Add Component: New Action.
  • Select "Set Elements Connect field value action"
  • In "Fields to set" list, select the Connect field you need to set.





  • Click "Save", name the automation rule, click "Turn it on".
  • Click "Run rule" (in the Audit log, you can check tickets that were updated).
  • Ensure that the field is well populated on the concerned tickets

By running a script

In ScriptRunner script console, paste the below script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

//Defining variables
def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");
def serviceValueClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");
def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceValueClass);
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()

//Build the JQL query to retrieve issues that needs to be updated
def query = jqlQueryParser.parseQuery("JQL_QUERY")

//Connect field to be set on issues, we can define variables as many Connect fields that needs to be set
def connectField = "customfield_XXXXX"
 
//Run JQL query
def queryResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

//Update issues, set Connect field
queryResults.getResults().each { myIssue ->
    fieldValueService.computeFieldsValue(myIssue.key, [connectField]);
}

This script should be adapted to match the user needs by updating the below:

  • JQL_QUERY: write the JQL query that will retrieve the issues where we will set the Connect field.
  • customfield_XXXXX: the Connect field ID.
  • If we need to set more that one field at the same time, we should add these lines of code:
def connectField2 = "customfield_ZZZZZ"
....
fieldValueService.computeFieldsValue(myIssue.key, [connectField2]);