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
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.IssueFieldConstantsimport com.atlassian.jira.issue.fields.FieldManagerFieldManager fieldManager = ComponentAccessor.fieldManagerdef parentIssue = issue.parentObjectdef 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)
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:-
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.
Regards,
Laurie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:-
This post-function sample is added to the Create transition and is added to the very bottom, as shown in the image below:-
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.
2. Once the issue is created, the value for the text field and the labels are visible
3. Next, a subtask is created. Only the Summary is added.
4. Once the subtask is created as expected, the values for the labels and sample text field are also included in the subtask.
I hope this helps to solve your question. :)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @LaurieC
If the solution provided solves your question, kindly accept the answer.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Thanks for your help!
Laurie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:-
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Thanks for your continued help. I just tested the file and I'm able to load it.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Any thoughts on what might be happening here?
Thanks!
Laurie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.