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

Need to create sub-tasks based on multiple select list custom field Edited

Hello ,

 

We have custom field states with multiple selection our requirement is when they select 4 states four sub-tasks has to be created.

Kindly help me with script by using built in create sub-task post function i'm able to create only one sub-task.

Note : That multiple custom field data is coming from Database through Elements we have configured that 

We need custom script post function when multiple values are selected that number of sub-tasks has to created

 

1 answer

Hi @Mahesh Kallepalli 

I would like to suggest you try Automation for JIRA plugin. You can simply customize the automation below to achieve your need:

Here's the background of the rule configured below

- A custom field with two possible options (Option 1 and option 2)

- The rule is triggered every time the custom field is changed

createsubtask.png

@Ganesh Babu 

 

I have achieved this through automation but my client is using only script runner they don't want to buy Automation plugin .

Have a look at https://library.adaptavist.com/search?page=1&term=create - there are several "create sub task" scripts there.

@Nic Brough _Adaptavist_ 

 

We written this code in custom script post function but only one sub-task is creating randomly based on selection , Could you please help us on this.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

import groovy.json.JsonSlurper

Issue parentIssue = issue
if (parentIssue.getIssueType().getName() == 'Sub task')
return

def cfState = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("State - Multi Select")
MutableIssue issueObject = ComponentAccessor.issueFactory.getIssue()
String statesString = (String) issue.getCustomFieldValue(cfState).toString();
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(statesString) as Map;
List states = parsedJson.get("keys") as ArrayList;
log.info(states)
if(states != null && issue.getIssueType().getName()=='RFP'){

for (int i = 0; i < states.size(); i++) {
issueObject.setProjectObject(issue.getProjectObject())
issueObject.setIssueTypeId("10503")
issueObject.setParentId(issue.getId())
issueObject.setSummary(states.get(i).toString())

def issueManager = ComponentAccessor.getIssueManager()
def subTask = issueManager.createIssueObject(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issueObject)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(issue, subTask, ComponentAccessor.jiraAuthenticationContext.getLoggedInUser())
}
}

@Nic Brough _Adaptavist_ 

 

Please find below errors that appear from log 

 

{
    "full.module.key": "com.onresolve.jira.groovy.groovyrunnerrungroovy-function (java.lang.String)",
    "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction (java.lang.String)",
    "class.name": "com.onresolve.jira.groovy.GroovyFunctionPlugin (java.lang.String)",
    "issue": "SOA-117 (com.atlassian.jira.issue.IssueImpl)",
    "passesCondition": "true (java.lang.Boolean)",
    "transientVars": {
        "entry": "com.opensymphony.workflow.spi.SimpleWorkflowEntry@2a55453d",
        "issue": "SOA-117 (com.atlassian.jira.issue.IssueImpl)",
        "configuration": "com.opensymphony.workflow.config.DefaultConfiguration@77dcd700",
        "context": "com.opensymphony.workflow.basic.BasicWorkflowContext@109c0bb0",
        "createdStep": "SimpleStep@17[owner=, actionId=0, status=Open] (com.opensymphony.workflow.spi.SimpleStep)",
        "originalissueobject": "null (org.codehaus.groovy.runtime.NullObject)",
        "actionId": "1 (java.lang.Integer)",
        "issueProperties": "{} (com.google.common.collect.RegularImmutableMap)",
        "currentSteps": "[SimpleStep@17[owner=, actionId=0, status=Open]] (java.util.ArrayList)",
        "pkey": "SOA (java.lang.String)",
        "store": "com.opensymphony.workflow.spi.ofbiz.OfbizWorkflowStore@1fffeada",
        "descriptor": "com.atlassian.jira.workflow.ImmutableWorkflowDescriptor@2d231512"
    },
    "log": "org.apache.log4j.Logger@4fcf25d5"
}

Suggest an answer

Log in or Sign up to answer
TAGS

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