I am trying to create subtasks based on checkbox selections made during a transition. I created a screen with the checkboxes custom field callled Subtasks. There are about 10 checkboxes for this field and I want when the user clicks OK on the screen, the post function automatically create subtasks based on the selected checkboxes.
Pseudocode:
Collection selectedChBx = get checked checkboxes;
for each selectedChBx
if selectedChBx.text = "Development (tech 1)"
create subtask with a task summary "Development (tech 1)"
else if selectedChBx.text = "Documentation (tech 1)"
create subtask with a task summary "Documentation (tech 1)"
next
Any guidance on how to pull in the selected checkboxes? Here is what I have thus far:
cfsubTasks = customFieldManager.getCustomFieldObjectByName("Subtasks")
Collection subTasks= (Collection) issue.getCustomFieldValue(cfsubTasks);
if(subTasks != null)
{
for(i in 0..subTasks.size()-1)
{
String subtaskNeeded = subTasks.get(i).getName();
if(subtaskNeeded = "Development (tech1)")
issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId("10")
issueObject.setParentId(issue.getId())
issueObject.setSummary("Development (tech1)")
subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject)
subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser())
i++
}
}
Community moderators have prevented the ability to post new answers.
First off, THANK YOU Jamie Echlin!!!!!
Finally got everything working. This will work with any number of choices, I just limited mine to 3 development and 2 documentation.
Final Script:
import com.atlassian.jira.issue.Issue import com.atlassian.jira.util.ImportUtils import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import java.lang.Boolean; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def issueFactory = ComponentAccessor.getIssueFactory() def issueManager = ComponentAccessor.getIssueManager() def authenticationContext = ComponentAccessor.getJiraAuthenticationContext() def subTaskManager = ComponentAccessor.getSubTaskManager() cfsubTasks = customFieldManager.getCustomFieldObjectByName("Subtasks") subTasks= (Collection) issue.getCustomFieldValue(cfsubTasks); if(subTasks != null) { for(i in 0..subTasks.size()-1) { def subtaskNeeded = subTasks.get(i).getValue(); if (subtaskNeeded.subSequence(0,11) == "Development") { issueObject = issueFactory.getIssue() issueObject.setProject(issue.getProject()) issueObject.setIssueTypeId("56") issueObject.setParentId(issue.getId()) if (subtaskNeeded == "Development (J2EE)") { issueObject.setSummary("Development (J2EE)") } else if (subtaskNeeded == "Development (C++)") { issueObject.setSummary("Development (C++)") } else if (subtaskNeeded == "Development (Database Activity)") { issueObject.setSummary("Development (Database Activity)") } } if (subtaskNeeded.subSequence(0,13) == "Documentation") { issueObject = issueFactory.getIssue() issueObject.setProject(issue.getProject()) issueObject.setIssueTypeId("57") issueObject.setParentId(issue.getId()) if (subtaskNeeded == "Documentation (Technical)") { issueObject.setSummary("Documentation (Technical)") } else if (subtaskNeeded == "Documentation (Functional)") { issueObject.setSummary("Documentation (Functional)") } } subTask = issueManager.createIssue(authenticationContext.getLoggedInUser(), issueObject) subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getLoggedInUser()) i++ } }
I am going to switch all the if statements to a switch statement
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem. Would probably be more helpful to others if you put that in the {code} macro, which would preserve the formatting.
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.
perfect, thanks ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I am close. I am now getting the following error, any ideas? I have called the CustomFieldManager.
[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: TEST-12345, actionId: 21, file: <inline script>
groovy.lang.MissingPropertyException: No such property: customFieldManager for class: Script203
at Script203.run(Script203.groovy:11)
here is my code:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import java.lang.Boolean;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
cfsubTasks = customFieldManager.getCustomFieldObjectByName("Subtasks")
subTasks= (Collection) issue.getCustomFieldValue(cfsubTasks);
log.warn ("subTasks: " + subTasks)
if(subTasks != null)
{
for(i in 0..subTasks.size()-1)
{
def subtaskNeeded = subTasks.get(i).getName();
if (subtaskNeeded.subSequence(0,11) == "Development")
{
issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId("56")
issueObject.setParentId(issue.getId())
if (cfsubTasks*.value.contains("Development (J2EE)"))
{ issueObject.setSummary("Development (J2EE)")}
else if (cfsubTasks*.value.contains("Development (C++)"))
{ issueObject.setSummary("Development (C++)")}
else if (cfsubTasks*.value.contains("Development (Database Activity)"))
{ issueObject.setSummary("Development (Database Activity)")}
}
if (subtaskNeeded.subSequence(0,13) == "Documentation")
{
issueObject = issueFactory.getIssue()
issueObject.setProject(issue.getProject())
issueObject.setIssueTypeId("57")
issueObject.setParentId(issue.getId())
if (cfsubTasks*.value.contains("Documentation (Technical)"))
{ issueObject.setSummary("Documentation (Technical)")}
else if (cfsubTasks*.value.contains("Documentation (Functional)"))
{ issueObject.setSummary("Documentation (Functional)")}
}
subTask = issueManager.createIssue(authenticationContext.getUser(), issueObject)
subTaskManager.createSubTaskIssueLink(issue.getGenericValue(), subTask, authenticationContext.getUser())
i++
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I added that and now I get the field values but, I got an error for: No such property: issueFactory for class so I added issueFactory = componentManager.getIssueFactory(). Now I get this error: No such property: componentManager for class
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
searching for the right syntax to initialize the componentManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def issueFactory = ComponentAccessor.getIssueFactory() don't use component manager, use the static methods on CompAcc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
At Stephen, I've given you two upvotes so that should give you enough to comment. use: authenticationContext.getLoggedInUser() instead of what you're using.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like you are mostly on the right track, give or take. Add some logging to your code so you can see where you are getting to then check the application log, eg
log.warn ("subTasks: " + subTasks)
etc. You can change the log level to debug later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.