Hi All,
I'm taking my first steps in script runner for jira, and though I've read (and tried) a lot questions & answers here , I'm still facing issues, so here goes:
I need to create a few tasks based on values of multi selection customized field, here are the details:
I have a custom field " Office" from type multi-selection list, let's say OfficeA, OfficeB, OfficeC.
When a task is created I need to create separate tasks, according to the selected values in the "Office" field. Each of those tasks must have the same field values as the original one, but Office" which needs to be marked with a single value which was selected.
For example: if selected values are OfficeA, OfficeB the result will be 2 (almost) identical tasks, the only difference is that one of them will be Office=OfficeA and the other Office = OfficeB.
After the creation of the additional tasks - I don't care about the original task, if it helps I can use it as one of the "new" tasks (with removal of redundant "Office" values)
No need in coping comments, links, etc. only the fields.
We use Jira server 8.5.6 , and script runner 6.16.0, I added a post function in the "create" transition which uses the "clone an issue, and links", currently I have in condition 'OfficeA' in cfValues['Office']. Value, but I don't know how to fill the "Office" value for the cloned task since it will also clone another task in its create transition L
A few question here:
Any assistance will be appreciated J
Thanks
Keren
I actually just did something similar, rather than a post function, I did it as a listener, as I need it to create tasks every time the checkbox field is updated. I would suggest that rather than using the same issue type, you make the new tasks subtasks of the original task (which is what I did). I have an issue type called Application Change Request and subtasks called Deployment Tasks. I have a field called Deployment Profiles that when updated is read and a Deployment Task created for each option selected. Below is my script for reference, it might help you in what you're trying to accomplish:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.issue.fields.screen.FieldScreenManager
import com.atlassian.jira.issue.fields.screen.FieldScreenLayoutItem
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.version.Version
import java.sql.Timestamp
def im = ComponentAccessor.getIssueManager()
//def parentIssue = im.getIssueObject("DIGCLM-91") //for debugging
MutableIssue parentIssue = event.issue as MutableIssue
if (parentIssue.getIssueType().name == "Application Change Request" && event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Deployment Profile(s)"})
{
def cfm = ComponentAccessor.getCustomFieldManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def stm = ComponentAccessor.getSubTaskManager()
def cm = ComponentAccessor.getConstantsManager()
def fm = ComponentAccessor.getFieldManager()
def fsm = ComponentAccessor.getFieldScreenManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def deploymentProfiles = cfm.getCustomFieldObjectsByName("Deployment Profile(s)")
def parentDeploymentProfiles = parentIssue.getCustomFieldValue(deploymentProfiles[0]) as List
def subTasks = parentIssue.getSubTaskObjects()
parentDeploymentProfiles.each { profile ->
boolean subtaskExists = false
subTasks.each { subtask ->
if (subtask.getSummary() == "Deployment Profile: " + profile as String)
{
subtaskExists = true
}
}
if (!subtaskExists)
{
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setAssigneeId(parentIssue.assigneeId)
newSubTask.setSummary("Deployment Profile: " + profile as String)
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setFixVersions(parentIssue.getFixVersions())
newSubTask.setReporter(currentUser)
def screen = fsm.getFieldScreen(13002 as Long)
def tab = screen.getTab(0)
def fields = fsm.getFieldScreenLayoutItems(tab)
fields.each { fieldLYOI ->
def field = fm.getField(fieldLYOI.getFieldId())
log.warn(field)
if (fm.isCustomField(field))
{
def cf = fm.getCustomField(fieldLYOI.getFieldId())
newSubTask.setCustomFieldValue(cf, parentIssue.getCustomFieldValue(cf))
}
}
newSubTask.setIssueTypeId(cm.getAllIssueTypeObjects().find{
it.getName() == "Deployment Task"
}.id)
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
im.createIssueObject(currentUser, newIssueParams)
stm.createSubTaskIssueLink(parentIssue as Issue, newSubTask as Issue, currentUser)
}
}
}
I probably should put more comments in there... lol
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.