Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to update sub-task siblings based on a sub-task custom field value

In short, we have a transition on sub-tasks that we would like to run on a specific set of sub-tasks depending on the value of a multi-select checkbox custom field on a sibling sub-task.

I'm trying to:

  1. Get the value of the checkbox that is presented on a transition on the "special" sub-task
  2. run some conditional code based on the values found that builds another list of issue types and transition ids
  3. use this dynamically generated list to update sibling sub-tasks.
  4. link the sibling sub-tasks to the "special" sub-task

I can't seem to get the parent key/id.
I'm not sure if I am creating the list correctly (is it .add or .push?)
The 'for(value in selectedActivities)' seems wrong

We are on Atlassian Cloud using a Scriptrunner post function.

Here is what I have so far (many cases omitted):

 


def amdSubtask = issue.key // The issue key of the study amendment subtask on which this script will run as a post function
def StudyIssueKey = issue.getParentObject()?.getKey() // get the parent issue key

// def selectedActivities = ["Protocol", "Budget", "Contract", "Coding", "Billing Grid", "Bellevue"]
def selectedActivities = issue.fields.customfield_11711 // get the set if values selected in the "Study Activities" custom field
logger.info("SELECTED " + selectedActivities)

def aList = [] // create a map of issue types to transition , and the transition ID for Initiate Study Amendment

for(value in selectedActivities)
// If Selected Activity = "Protocol" then add the following issue types to the aList
switch (value){

case "Protocol":
aList.add("Protocol - Development":11)
break;
case "Budget":
aList.add("Budget":11)
break;
}


logger.info("List of Subtask Types: " + aList)

// Retrieve all the subtasks of the parent
def allSubtasks = get("/rest/api/2/search")
.queryString("jql", "parent=${StudyIssueKey}")
.queryString("fields", "issuetype")
.asObject(Map)
.body
.issues as List<Map>
logger.info("Total subtasks for ${StudyIssueKey}: ${allSubtasks.size()}")


//Now run the transition on the subtask issue types in the map
for (subtask in allSubtasks) {
// get subtask key
def subtaskKey = subtask.key
// Transition issue if ID is not 0, otherwise continue with loop
if (aList.getAt(subtask.fields.issuetype.name)){
post("/rest/api/2/issue/${subtaskKey}/transitions")
.header("Content-Type", "application/json")
.body([
"transition": [
"id": aList.getAt(subtask.fields.issuetype.name) // The transition might be 11 for all, in which case, we can just use 11 and remove transition id from list
]
])
.asString()
logger.info(subtask.fields.issuetype.name + " do transition " + aList.getAt(subtask.fields.issuetype.name))

//Link to the Study Amendment subtask
post('/rest/api/2/issueLink')
.header('Content-Type', 'application/json')
.body([
type: [ name: "Amendment" ],
outwardIssue: [ id: amdSubtask ], // "is Amended by (amdSubtask)
inwardIssue: [ key: subtaskKey ] // is Amendment to (subtask)
])
.asString()
}
else{
logger.info("Transition not available " + subtask.fields.issuetype.name)
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Do Not Lose your Customer’s Trust

Missing deadlines is one of the biggest problems every team lead wants to avoid when dealing with managed services. When the customer contracts your company to help with IT services it is expected th...

24 views 0 0
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you