I have three statuses in a workflow with 6 subtasks each. i want to create the subtasks upon transition. i found this https://library.adaptavist.com/entity/create-sub-tasks-when-an-issue-is-created but its marked as cloud. will this work on server? my plan is to add the script separately to each transition.
There's a lot of code there, I'm struggling to work through what it is trying to do.
If I were to cut it down to the bare bones though, all you really need in a post-function is below. You don't need to set the status, that happens automatically on creation, and you should be able to add setDescription("") to this as well.
def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(issue.projectObject.id)
setIssueTypeId(subTaskIssueType.id)
setReporterId(reporter.key)
setSummary(summary)
}
def validationResult = issueService.validateSubTaskCreate(loggedInUser, issue.id, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection
def issueResult = issueService.create(loggedInUser, validationResult)
assert issueResult.valid : issueResult.errorCollection
I'm close.... any thoughts on why this isnt working?
import com.atlassian.jira.component.ComponentAccessor
def issueInputParameters = issueService.newIssueInputParameters().with
{
setProjectId(issue.projectObject.id)
setIssueTypeId(subTaskIssueType.id)
setReporterId(reporter.key)
setsummary('SPS Project team recruitment', 'SPS Project team introductory meeting', 'Location selection', 'Introductory Location meeting', 'SPS Project team review of interviews')
}
def validationResult = issueService.validateSubTaskCreate(loggedInUser, issue.id, issueInputParameters)
assert validationResult.valid : validationResult.errorCollection
def issueResult = issueService.create(loggedInUser, validationResult)
assert issueResult.valid : issueResult.errorCollection
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Er, you can't set five summaries for a single issue.
You need to look through this 5 times, changing the summary on each iteration
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in the original script above (with all the extra stuff) we defined a list of summaries and that worked. trying to figure out what i can cut out of that one to make it work but NOT have it run for epics.
def listOfsummaries = ['Subtask summary 1', 'Subtask summary 2'] // The summaries to use for
def issueType = "Sub-task" // The Sub Task Issue Type to Use
// Get the sub task issue type to use
//def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
//assert issueTypeId: "No subtasks issue type found called '${issueType}'"
// Get the project to create the subtask in
//def project = (issue.fields as Map).project
listOfsummaries.forEach { summary ->
// Create the subtask
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(destinationProjectId)
.setIssueTypeId(subTaskIssueTypeId)
.setSummary(summary)
//.setReporterId(reporterId)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, your original script had a loop in it, which you have re-implemented here, so it'll go through several creations.
But you've commented out all the stuff that works out other parameters you need in the create.
To avoid this running for Epics, look at the issue type for the current issue first, and exit if it's Epic
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.
we got this far but are still getting errors:
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
//import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import groovy.json.JsonSlurper
import groovy.json.*
import org.apache.http.client.methods.*
import org.apache.http.entity.*
import org.apache.http.impl.client.*
import org.apache.xpath.operations.String
import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CloneIssue
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.jira.component.ComponentAccessor
//import com.atlassian.jira.ComponentManager - deprecated https://scriptrunner.adaptavist.com/5.4.49-jira8/jira/releases/UpgradingToJira8.html#_componentmanager_has_been_moved
//import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.DefaultIssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.event.type.EventDispatchOption
def subTaskIssueTypeId = 5
//get current user
//def currentUserObject = ComponentAccessor.getJiraAuthenticationContext().getUser()
//def currentUser = currentUserObject.username
//Set CommentManager object
//def commentManager = ComponentAccessor.getCommentManager()
//Create IssueManager object
//def issueManager = ComponentAccessor.getIssueManager()
//Create Custom Field Manager object
//def customFieldManager = ComponentAccessor.getCustomFieldManager()
//Create Issue Service Manager Object
//IssueService issueService = ComponentAccessor.getIssueService();
//def projectManager = ComponentAccessor.getProjectManager()
//def defaultStatusId = "1" //Open
//set issue variable
//Issue issue = issue;
def communityFieldId = "customfield_14000" //Community
//def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def projectManager = ComponentAccessor.getProjectManager()
def CommentManager commentMgr = ComponentAccessor.getCommentManager();
//def issue = ComponentAccessor.getIssueManager().getIssueObject(parentId)
//Issue issue = event.getIssue()
//Issue issue = issue
log.warn("issue: " + issue)
//Get destination project key
def communityField = customFieldManager.getCustomFieldObject(communityFieldId)
def destinationProjectKey = issue.getCustomFieldValue(communityField).toString()
def originalIssueKey = issueManager.getIssueByCurrentKey(issue.key)
//get destination project info
def destinationProjectObj = projectManager.getProjectObjByKeyIgnoreCase(destinationProjectKey.replace('Project: ',''))
def destinationProjectId = destinationProjectObj.getId()
def destinationProjectLead = destinationProjectObj.getProjectLead()
def destinationProjectLeadObj = ComponentAccessor.getUserUtil().getUserByKey(destinationProjectLead.username)
//get current user
def currentUserObject = ComponentAccessor.getJiraAuthenticationContext().getUser()
//def currentUser = currentUserObject.username
//TODO: get project lead of assigned community
def reporterId = issue.getReporterId()
//If issue is a subtask, script is not executed
//if (issue.fields.issuetype.subtask) {
// return
//}
log.warn("issue type: " + issue.issueType.name)
if(issue.issueType.name == "Subtask"){
return
}
log.warn("Current User: " + currentUser)
log.warn("Source Issue Key: " + originalIssueKey)
log.warn("Source Issue Reporter: " + reporterId)
log.warn("Destination Project Key: " + destinationProjectKey)
log.warn("Destination Project Id: " + destinationProjectId.toString())
//get destination project info
// New created issue
def issueKey = issue.key
// Get the issue
//def issueResp = get("/rest/api/2/issue/${issueKey}").asObject(Map)
//assert issueResp.status == 200
//def issue = issueResp.body as Map
// Get the issue types for the instance
//def typeResp = get('/rest/api/2/issuetype').asObject(List)
//assert typeResp.status == 200
//def issueTypes = typeResp.body as List<Map>
def listOfsummaries = ['Subtask summary 1', 'Subtask summary 2'] // The summaries to use for
def issueType = "Sub-task" // The Sub Task Issue Type to Use
// Get the sub task issue type to use
//def issueTypeId = issueTypes.find { it.subtask && it.name == issueType }?.id
//assert issueTypeId: "No subtasks issue type found called '${issueType}'"
// Get the project to create the subtask in
//def project = (issue.fields as Map).project
listOfsummaries.forEach { summary ->
// Create the subtask
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setProjectId(destinationProjectId)
.setIssueTypeId(subTaskIssueTypeId)
.setSummary(summary)
//.setReporterId(reporterId)
.setDescription("teset")
.setStatusId(defaultStatusId)
//.setAssigneeId(destinationProjectLead.username)
//.addCustomFieldValue(timeCategoryFieldId, defaultTimeCategory)
//.addCustomFieldValue(epicNameFieldId, currentIssueSummary)
//.addCustomFieldValue(parentLinkFieldId, parentLinkDefaultValue)
IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(currentUserObject, issue.getId(), issueInputParameters);
if(updateValidationResult.isValid()) {
IssueResult updateResult = issueService.update(currentUserObject, updateValidationResult);
}
// Get and validate the newly created subtask
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Joey Klein yes script runner add-on is available for Jira cloud as well for Jira server version.
You can write separate script to create sub-task at particular transition for your workflow.
You can search more about it on https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?hosting=cloud&tab=overview
Thanks!
Best,
Narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Narendra Kumar , appreciate the fast response. I have the app for server. I was referring specifically to the script i pasted which says its for cloud.
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.