Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,466,252
Community Members
 
Community Events
176
Community Groups

Copying fields from parent to subtask with scriptrunner isn't allowing unique labels on subtasks

I'm using a scriptrunner script on the create screen of a subtask to copy down some of the values from the parent issue to the subtasks. One of those used to be the label field, but our team has decided they no longer want that. I removed the 

issue.setLabels(parentIssue.labels)
code from my script, but it still isn't allowing me to load labels on the subtasks.
Here is the rest of my code. Is there something in here that is stopping me from loading labels on the subtasks?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.FieldManager
FieldManager fieldManager = ComponentAccessor.fieldManager
def parentIssue = issue.parentObject
def customfield2 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Data Elements")
def parentissueCustomFieldValue2 = parentIssue.getCustomFieldValue(customfield2)
issue.setCustomFieldValue(customfield2, parentissueCustomFieldValue2)
def customfield4 = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Test Type")
def parentissueCustomFieldValue4 = parentIssue.getCustomFieldValue(customfield4)
issue.setCustomFieldValue(customfield4, parentissueCustomFieldValue4)
issue.setPriority(parentIssue.priority)

Thanks in advance!
Laurie

1 answer

Hi @LaurieC

From your description, I assume you are using the Post-Function with ScriptRunner's Create a sub-task option. Is this correct?

If so, could you please share a screenshot of your Post-Function configuration? It should be something like:-

post_function_config.png

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_

Thanks for asking.

I'm actually just using a custom Scriptrunner post function. An individual would create the subtask themselves and I have this post function on the create step of this type of subtask to copy some of the values from the parent to the subtask.

2022-08-01_7-57-20.png

Regards,

Laurie

Hi @LaurieC

I have run a basic test in my environment using ScriptRunner's Custom script post-function, and I could copy both the field value and the Label values from the Parent to the Sub-Task.

Below is the code that I have tested:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def sampleTextField = customFieldManager.getCustomFieldObjectsByName('Sample Text Field').first()

if (issue.isSubTask()) {
def parentIssue = issue.parentObject
issue.setLabels(parentIssue.labels)
issue.setCustomFieldValue(sampleTextField, parentIssue.getCustomFieldValue(sampleTextField))
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Post-Function configuration:-

config.png

This post-function sample is added to the Create transition and is added to the very bottom, as shown in the image below:-

config2.png

Below are a few test screenshots:-

1. A story-type issue is created, and some labels and a value for the Sample Text Field are added.

test1.png

2. Once the issue is created, the value for the text field and the labels are visible

test2.png

3. Next, a subtask is created. Only the Summary is added.

test3.png

4. Once the subtask is created as expected, the values for the labels and sample text field are also included in the subtask.

test4.png

I hope this helps to solve your question. :)

Thank you and Kind regards,

Ram

Hi @LaurieC

If the solution provided solves your question, kindly accept the answer.

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thanks so much for the code, description and screen shots! 

Unfortunately, my problem is that I don't want to carry the labels from the parent to the child and the system is still doing it when I load a csv with a parent and sub-tasks it is not loading the labels for the subtasks. Only the parent.

Any thoughts?

Thanks again!
Laurie

Hi @LaurieC

Is it possible to share an example csv so I can try to test it in my environment?

Thank you and Kind regards,

Ram

Hi Ram,

I am able to load unique labels on subtasks of action items. I'm unable to do the same on our Test and Test Step (subtask) issue types. See below CSV and screen shot.

Issue ID,Issue Type,Summary,Parent ID,Labels,Test Type
AI-001,Action Item,Action Item parent ,,Parent_label,
AI-002,Subtask,AI Child with label 1,AI-001,Child_1,
AI-003,Subtask,AI Child with label 2,AI-001,Child_2,
Test-001,Test,Test parent ,,Parent_label,Unit Test
Test-002,Test Step,Test Step Child with label 1,Test-001,Child_1,Unit Test
Test-003,Test Step,Test Step Child with label 2,Test-001,Child_2,Unit Test

 

Snag_a15ffa3.png

Thanks for your help!
Laurie

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

I used to have code in my postscript to copy down the labels from the parent to child:

issue.setLabels(parentIssue.labels)
but I have since removed it and it is still not allowing me to load unique labels to the children. 
Any ideas?
Thanks!
Laurie

Hi @LaurieC

I need to clarify with you, i.e. can you confirm that when you import the issues via the CSV, you are not encountering any errors?

I have tried to import the CSV that you have shared, and I keep getting this error message:-

image_2022-08-23_203500836.png

Only 4 out of the 6 issues are created, and two subtasks are ignored.

Please share if there is any other configuration required.

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thanks for your continued help. I just tested the file and I'm able to load it.2022-08-25_7-30-02.png

Here's the configuration file contents.

{
"config.version" : "2.0",
"config.project.from.csv" : "false",
"config.encoding" : "UTF-8",
"config.email.suffix" : "@",
"config.field.mappings" : {
"Issue Type" : {
"jira.field" : "issuetype"
},
"Parent ID" : {
"jira.field" : "subtask-parent-id"
},
"Summary" : {
"jira.field" : "summary"
},
"Labels" : {
"jira.field" : "labels"
},
"Issue ID" : {
"jira.field" : "issue-id"
},
"Test Type" : {
"existing.custom.field" : "11203"
}
},
"config.value.mappings" : { },
"config.delimiter" : ",",
"config.project" : {
"project.type" : null,
"project.key" : "WDP",
"project.description" : null,
"project.url" : null,
"project.name" : "W Demo Project",
"project.lead" : "laurie.c"
},
"config.date.format" : "dd/MMM/yy h:mm a"
}

Note that Test Step issue type is a subtask under the Test issue type.

Thanks,
Laurie

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Any thoughts on what might be happening here?

Thanks!
Laurie

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events