Hello,
I am asked to update the script that Thanos Batagiannis [Adaptavist] has provided. Please see it below.
We would like to have subtask 1 and 2 with descriptions as it stated below ( samples) every time we receive new employee ticket. Is it possible to have subtask 1 and 2 with the descriptions ?
Your help is greatly appreciated.
Description for Subtask 1:
To Do List 1
Description for Subtask 2:
To Do list 2:
Here is the script below;
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.user.ApplicationUser def parentIssue = event.issue if (parentIssue.getIssueType().getName() != 'New Employee') return def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def summariesList = ["Subtask 1", "Subtask 2", "Notify the Risk Team of New Employee", "Subtask 3"] def issueFactory = ComponentAccessor.getIssueFactory() def subTaskManager = ComponentAccessor.getSubTaskManager() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() def userManager = ComponentAccessor.getUserManager() def watcherManager = ComponentAccessor.getWatcherManager() Issue Notify_the_Risk_Team_of_New_Hire //here we fill an array with all required watchers List<ApplicationUser> newWatchers = new ArrayList<>() newWatchers.add(userManager.getUserByName("susie")) newWatchers.add(userManager.getUserByName("elif")) newWatchers.add(userManager.getUserByName("luiz")) summariesList.each { subTaskSummary -> MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(subTaskSummary) newSubTask.setParentObject(parentIssue) newSubTask.setPriorityId(constantManager.getPriorities().find { it.getName() == "Major" }?.id) newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) // Add any other fields you want for the newly created sub task //if the summary is Notify¬_the_Risk_Team_of_New_Hire then if (subTaskSummary.equals("Notify the Risk Team of New Hire")) { def assignee = userManager.getUserByName("susie") newSubTask.setAssignee(assignee) Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> Notify_the_Risk_Team_of_New_Hire = issueManager.createIssueObject(user, newIssueParams) as Issue subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) } else { Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) } log.info "Issue with summary ${newSubTask.summary} created" } if (Notify_the_Risk_Team_of_New_Hire) { newWatchers.each { watcherManager.startWatching(it, Notify_the_Risk_Team_of_New_Hire) } }
It's pretty straightforward to set the description on an issue. In your case, after you create the newSubTask variable as an issue, just use the .setDescription method (or Groovier yet .description=
):
newSubTask.description = """My Multiline Description here"""
Since you're iterating through a list of summaries, you may need to change your data structure a bit so that you can specify both the description and the summary. A simple Map would probably do it:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.user.ApplicationUser def parentIssue = event.issue if (parentIssue.getIssueType().getName() != 'New Employee') return def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def bigDescription = """ * Active Application Add-ins: Lists the extensions that are registered and currently running in your Office program. * Inactive Application Add-ins: Lists the add-ins that are present on your computer but are not currently loaded. For example, smart tags or XML Schemas are active only when the document that references them is open. Another example is the COM add-ins that are listed in the COM Add-ins dialog box. If the check box for a COM add-in is selected, the add-in is active. If the check box for a COM add-in is cleared, the add-in is inactive. To learn how to open the COM Add-in dialog box, see the section called [Turn off or manage the installed add-ins|https://support.office.com/en-us/article/Enable-or-disable-add-ins-in-Office-programs-3e533d0f-a6cf-44b7-b6b4-3d9185b5e025?ui=en-US&rs=en-US&ad=US&fromAR=1#bm2]. * Document Related Add-ins: Lists template files that are referenced by currently open documents. * Disabled Application Add-ins: Lists add-ins that were automatically disabled because they are causing Office programs to crash. """ def summariesList = ["Subtask 1" : bigDescription, "Subtask 2" : bigDescription, "Notify the Risk Team of New Employee" : "", "Subtask 3": ""] def issueFactory = ComponentAccessor.getIssueFactory() def subTaskManager = ComponentAccessor.getSubTaskManager() def constantManager = ComponentAccessor.getConstantsManager() def issueManager = ComponentAccessor.getIssueManager() def userManager = ComponentAccessor.getUserManager() def watcherManager = ComponentAccessor.getWatcherManager() Issue Notify_the_Risk_Team_of_New_Hire //here we fill an array with all required watchers List<ApplicationUser> newWatchers = new ArrayList<>() newWatchers.add(userManager.getUserByName("susie")) newWatchers.add(userManager.getUserByName("elif")) newWatchers.add(userManager.getUserByName("luiz")) summariesList.each { subTaskSummary, subTaskDescription -> MutableIssue newSubTask = issueFactory.getIssue() newSubTask.setSummary(subTaskSummary) newSubTask.setParentObject(parentIssue) newSubTask.setPriorityId(constantManager.getPriorities().find { it.getName() == "Major" }?.id) newSubTask.description = subTaskDescription newSubTask.setProjectObject(parentIssue.getProjectObject()) newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{ it.getName() == "Sub-task" }.id) // Add any other fields you want for the newly created sub task //if the summary is Notify¬_the_Risk_Team_of_New_Hire then if (subTaskSummary.equals("Notify the Risk Team of New Hire")) { def assignee = userManager.getUserByName("susie") newSubTask.setAssignee(assignee) Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> Notify_the_Risk_Team_of_New_Hire = issueManager.createIssueObject(user, newIssueParams) as Issue subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) } else { Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object> issueManager.createIssueObject(user, newIssueParams) subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user) } log.info "Issue with summary ${newSubTask.summary} created" } if (Notify_the_Risk_Team_of_New_Hire) { newWatchers.each { watcherManager.startWatching(it, Notify_the_Risk_Team_of_New_Hire) } }
A few things of note:
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.