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
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
I have achieved this through automation but my client is using only script runner they don't want to buy Automation plugin .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look at https://library.adaptavist.com/search?page=1&term=create - there are several "create sub task" scripts there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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())
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
}
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.