You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I was wondering if there is a way to end a postfunction script if a condition is met. In the case below if if (input1 == 'NOT APPLICABLE') i need it to end this script and continue on with the other postfunctions in my create transition. Currently if i use the value 'NOT APPLICABLE' the script errors out and the other post functions do not process.
// get custom fields
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>
def fields = issue.fields as Map
logger.info("${fields}")
def projectKey = issue.fields.project.key
logger.info("${projectKey}")
def inputprojecttype = customFields.find { it.name == 'PIA Project' }?.id
logger.info("${inputprojecttype}")
def subjectident = customFields.find { it.name == 'Subject' }?.id
logger.info("${subjectident}")
def project = fields.project as Map
logger.info("${project}")
def input1 = issue.fields[inputprojecttype].value as String
logger.info("${input1}")
def subjectval = fields[subjectident] as String
logger.info("${subjectval}")
def queuedissueparent
if (input1 != 'NOT APPLICABLE'){
if (input1 == 'Rapid Design Engagement'){
queuedissueparent = 'BPIA-1132'
}
else
if (input1 == 'Fixed Wireless') {
queuedissueparent = 'BPIA-1133'
}
else
if (input1 == 'Head End') {
queuedissueparent = 'BPIA-1134'
}
else
if (input1 == 'Conduit Design') {
queuedissueparent = 'BPIA-1135'
}
else
if (input1 == 'Subdivision GIS Design') {
queuedissueparent = 'BPIA-1136'
}
else
if (input1 == 'Business Readiness') {
queuedissueparent = 'BPIA-1137'
}
else
if (input1 == 'OSP') {
queuedissueparent = 'BPIA-1138'
}
else
if (input1 == 'Confluence Space Standardization') {
queuedissueparent = 'BPIA-1139'
}
else
if (input1 == 'Contracts') {
queuedissueparent = 'BPIA-1140'
}
else
if (input1 == 'Change Orders') {
queuedissueparent = 'BPIA-1141'
}
else
if (input1 == 'Department User Dashboards') {
queuedissueparent = 'BPIA-1142'
}
else
if (input1 == 'Departmental Dashboards') {
queuedissueparent = 'BPIA-839'
}
else
if (input1 == 'EPP') {
queuedissueparent = 'BPIA-1143'
}
else
if (input1 == 'Feasibility') {
queuedissueparent = 'BPIA-368'
}
else
if (input1 == 'Member Dashboards') {
queuedissueparent = 'BPIA-1145'
}
else
if (input1 == 'Member Project Information Updates') {
queuedissueparent = 'BPIA-1161'
}
else
if (input1 == 'Regional Dashboards') {
queuedissueparent = 'BPIA-1146'
}
else
if (input1 == 'Revamp the PIA Request Process') {
queuedissueparent = 'BPIA-1147'
}
else
if (input1 == 'IMS Training Process Documentation') {
queuedissueparent = 'BPIA-1144'
}
else
if (input1 == 'IMS Member Rollout') {
queuedissueparent = 'BPIA-197'
}
}
logger.info("${queuedissueparent}")
// fetch issue objects from key (queuedissueparent)
def issueResp = get("/rest/api/2/issue/${queuedissueparent}")
.asObject(Map)
assert issueResp.status == 200
def issue = issueResp.body as Map
def typeResp = get('/rest/api/2/issuetype')
.asObject(List)
assert typeResp.status == 200
def issueTypes = typeResp.body as List<Map>
def issueType = "PIA Request Subtask" // 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
logger.info("${issueTypeId}")
assert issueTypeId : "No subtasks issue type found called '${issueType}'"
// Get the project to create the subtask in
// Create the subtask
def resp = post("/rest/api/2/issue")
.header("Content-Type", "application/json")
.body(
fields: [
project: project,
issuetype: [
id: issueTypeId
],
parent: [
"key" : "${queuedissueparent}"],
summary: subjectval
])
.asObject(Map)
// Get and validate the newly created subtask
def subtask = resp.body
assert resp.status >= 200 && resp.status < 300 && subtask && subtask.key != null
// If the sub task created successfully return a success message along with its key
if (resp.status == 201) {
return 'Success - Sub Task Created with the key of ' + resp.body.key.toString()
} else {
return "${resp.status}: ${resp.body}"
}
I don't use the cloud, but I assume that this should work (near the top)
if (input1 == 'NOT APPLICABLE') {
return
}
I can't believe it was that simple. I think I was using return; without the value brackets and that's why everything was erroring out. Thank you for your help!
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.