Forums

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

Is it possible to auto-populate Elements Connect Configuration fields (Nfeeds) from parent issue

Sruthi Biju April 4, 2022

Is it possible to auto-populate Elements Connect Configuration fields (Nfeeds) from parent issue to child issue using groovy scripting (Behaviours/Listeners - ScriptRunner plugin)

Case 1 - From Epic to Feature 

Case 2 - From Feature to User Story (Parent - subtask relation)

The user must see the auto-populated values at the Create screen itself

1 answer

1 vote
Simon Laffont
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.
April 4, 2022

Hello @Sruthi Biju

I am part of the Elements Connect Support team.

When using a Listener, what you are asking for is possible using the Elements Connect API, based on the following examples: ScriptRunner - Use Elements Connect API in a script 

This can be done by configuring the following Listener:

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue;

def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");
def serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");

def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass);

def parentFieldId = "customfield_10403";
def childFieldId = "customfield_10404";
def parentFieldKey = fieldValueService.getFieldValues(issue.key, parentFieldId);

if(parentFieldKey){
    return fieldValueService.computeFieldsValue(issue.key, [childFieldId]);
}
else{
    return -1;
}

(i) Please replace customfield_10403 and customfield_10404 according to your own configuration.


Behaviours work differently and it's not possible to use our Elements Connect API in such a script.

Furthermore, it wasn't possible to populate a Connect field in any way until version 6.11, in which the following Change Request has been released: CO-3116 - It shall be possible to set the value of an Elements Connect field with Behaviours (ScriptRunner) 

I advise you to read the following documentation on this subject: Can Elements Connect fields be manipulated from a ScriptRunner Behaviours script? 

Please let me know if further help is needed.

Kind regards,
Simon.

Sruthi Biju April 4, 2022

Hi @Simon Laffont ,

In both parent and child issues we have the same Nfeed field. We need to autopopulate the value we have selected in parent issue to the same Nfeed field we have maintained for child issue as well.

For e.g.: 

Nfeed field : customfield_10403

In Parent captured some value for Nfeed field : customfield_10403 as "abc"

In child we need the value "abc" for same Nfeed field : customfield_10403

Kind regards,

Sruthi Biju

Simon Laffont
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.
April 5, 2022

Hi @Sruthi Biju

Alright, so here is the Listener that you could set up:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager

SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();

def issue = event.issue;
 
def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");
def serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");

def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass);

def connectFieldId = "customfield_10403";

def parentFieldValue = fieldValueService.getFieldValues(issue.key, connectFieldId);

Collection subTasks = issue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
    subTasks.each {
        log.warn(issue.key+' has a subtask:' + it.getKey())  
        fieldValueService.setFieldValue(it.getKey(), connectFieldId, parentFieldValue);
        log.warn('Connect field has been updated in '+ it.getKey())  
    }
}

This way, the Connect field will be updated in all subtasks of an issue.

I configured this Listener to be triggered on the Issue Updated event.

Please let me know if it works on your end.

Kind regards,
Simon.

Sruthi Biju April 5, 2022

Hi @Simon Laffont ,

Tried to add the Custom listener in Jira (Data centre), but getting the static type checking errors. I anyway tried adding Issue Created and Issue Updated events, but the script didn't work as expected.

Subtasks_Issue.JPG

Regards,

Sruthi Biju

Simon Laffont
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.
April 5, 2022

@Sruthi Biju

The error messages on line 6 and 18 are probably because you didn't select any events:
event in Listener.png

If no event is selected, then the event.issue variable cannot be evaluated.


And the error messages displayed on lines 16 and 22 should be ignored. They are due to the Elements Connect classes (lines 9 and 10) that are not correctly interpreted by the Scriptrunner compiler. These are false positives and don't prevent the script from running properly.

This is explained in the following documentation: "Cannot find matching method" error message 
Cannot find matching method.png

Kind regards,
Simon.

Sruthi Biju April 5, 2022

Hi @Simon Laffont 

I have already added the events and still the listener doesn't work while creating the subtask issue and at the create screen of the subtask.

Subtasks_Issue_01.JPG

Regards, 

Sruthi Biju

Simon Laffont
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.
April 6, 2022

Hi @Sruthi Biju

I don't understand why an error message is displayed for the event.issue. It should work, as mentioned in the Scriptrunner documentation:

You should contact the Adaptavist support team about this issue.


Apart from that, the Issue Updated event is only triggered when an issue is edited. For this listener to be triggered when an issue is created, you need to add the Issue Created event.

Furthermore, a Listener cannot be triggered when the Create screen is opened because a Listener is event-based and can only be trigerred once the issue has been created, not before.

To execute a script when a screen is opened, you need to use a Behavior script.

Kind regards,
Simon.

Suggest an answer

Log in or Sign up to answer