Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Mahesh Kallepalli
Contributor
January 20, 2020

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

0 votes
Ganesh Babu
Community Champion
January 20, 2020

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

Mahesh Kallepalli
Contributor
January 20, 2020

@Ganesh Babu 

 

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

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2020

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

Mahesh Kallepalli
Contributor
January 21, 2020

@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())
}
}

Mahesh Kallepalli
Contributor
January 21, 2020

@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