I was able to piece together a script that generates multiple sub tasks when the parent issue is created. That being said, I need to be able to transfer some of the fields from the parent issue over to the sub tasks but have not been able to do so.
I used the lines below as suggested by other posts with no success.
//def custom fields
def cf_SepDate = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Separation Date")
def cf_Position = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Position Series & Grade")
def cf_reason = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Reason For Separation")
//custom fields values
def cfv_SepDate = issue.getCustomFieldValue(cf_SepDate) as Date
String cfv_Position = issue.getCustomFieldValue(cf_Position)
Option cfv_reason = (Option) issue.getCustomFieldValue(cf_reason)
//creates the subtask
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary(summary)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setDescription(parentIssue.description)
ApplicationUser userA = ComponentAccessor.getUserManager().getUserByName(assignee[i])
log.warn("Assigned User: " + userA.displayName)
newSubTask.setAssignee(userA)
newSubTask.setReporter(userA)
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == issuetypes[i]}.getId())
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
/*below are the lines of code that I am having issues with.
newSubTask.setCustomFieldValue(cf_SepDate, cfv_SepDate)
newSubTask.setCustomFieldValue(cf_Position, cfv_Position)
newSubTask.setCustomFieldValue(cf_reason, cfv_reason)
Is there any other way to transfer these fields without the use of add-ons? Jira is not showing any error message when the script runs.
Thanks in advance for any help
@Sebastian Gomez , I'd need to dig around in my scripts (and will if this doesn't get you going) to find the exact syntax but what is happening is the fields are set but you haven't told the DB about it yet. You'll need to add an update step to update the subtasks which will commit the value and generate an issue updated event.
IissueManager.updateIssue(user, newSubTask, EventDispatchOption.ISSUE_UPDATED, true) think you need something like this:
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.
when I tried adding issueManager.updateIssue(user, newSubTask, EventDispatchOption.ISSUE_UPDATED, true) to the end, the script stopped working and it doesn't create any sub-tasks.
The script above is currently running inside an if loop, letting Jira know that if parent issue type is submitted by a user, it needs to create 24 sub-tasks, and I want several fields from the parent issue to be copied over to all of the 24-sub-tasks at the moment of creation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried the line below without success.
UpdateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sebastian Gomez , Without seeing all of your changed code, I am guessing that you need to put the update statement inside the iterative loop that is writing the values to each issue...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the help @Mike Rathwell
also able to copy the fields correctly from the parent issue to the subtasks by making the following change:
// Since .getIssue() only creates a blank sub-task
MutableIssue newSubTask = issueFactory.getIssue()
We decided to use .cloneIssueWithAllFields instead. Now the correct fields are transferring over to the sub tasks when they get created.
MutableIssue newSubTask = issueFactory.cloneIssueWithAllFields(parentIssue)
Jira Documentation:
https://docs.atlassian.com/software/jira/docs/api/7.1.9/com/atlassian/jira/issue/IssueFactory.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.