I am trying to create sub-tasks based on custom field checkboxes and need a little bit of guidance on how to setup the post-function and writing the condition.
I have created a custom field called "SAP Access?" with 3 checkbox options, BI/PI/ECP, I'd like to create sub-tasks on the condition that the checkboxes are ticked and auto-assign them.
There are post-task functions written that pre-date me but I have tried to copy the formatting and tailored it. Can I get some feedback on whether below is correctly written?
//Get SAP Access checkbox value
def sapaccesscustomFieldObject = customFieldManager.getCustomFieldObjectsByName("SAP Access?")
//get all values of the custom field
def sapaccesscustomFieldValues = sapaccesscustomFieldObject.getValue(parentIssues)
//loop through values and create sub tasks
sapaccesscustomFieldValues.each { LazyLoadedOption it ->
def sapaccessValue = it.getValue()
switch (sapaccessValue){
case "SAP BI":
assigneIdList.add("User1")
summariesList.add("SAP BI access for new hire")
descriptionList.add("SAP BI access required")
break
case "SAP PI":
assigneIdList.add("User2")
summariesList.add("SAP PI access for new hire")
descriptionList.add("SAP PI access required")
break
case "SAP ECP":
assigneIdList.add("User3")
summariesList.add("SAP ECP access for new hire")
descriptionList.add("SAP ECP access required")
break
}
}
Hello @Jh
try with this code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userManager = ComponentAccessor.getUserManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def customfieldManager = ComponentAccessor.getCustomFieldManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()
def customField = customfieldManager.getCustomFieldObjectByName("SAP Access?")
def selectedValues = issue.getCustomFieldValue(customField)
def userBi = userManager.getUserByName("User BI")
def userPi = userManager.getUserByName("User PI")
def userEcp = userManager.getUserByName("User ECP")
selectedValues.each { value ->
MutableIssue newSubTask = issueFactory.getIssue()
switch(value) {
case "SAP BI":
newSubTask.setSummary("SAP BI access for new hire")
newSubTask.setDescription("SAP BI access required")
newSubTask.setAssignee(userBi)
case "SAP PI":
newSubTask.setSummary("SAP PI access for new hire")
newSubTask.setDescription("SAP PI access required")
newSubTask.setAssignee(userPi)
case "SAP ECP":
newSubTask.setSummary("SAP ECP access for new hire")
newSubTask.setDescription("SAP ECP access required")
newSubTask.setAssignee(userEcp)
}
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task" // or the type you want to use
}.id)
Map<String,Object> newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
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.