I am working on a workflow for employee terminations and would like to do the following:
Issue contains:
When the parent ticket is created the workflow will create a sub-task for each action that needs to be performed for that user. Each sub-task will be assigned to the appropriate person to handle the action. I am planning on using components for this purpose and make the component lead be the person that is responsible for the item.
I would like to use the Script Runner post function that creates sub-tasks and set the following but I am not familar with the scripting needed to do the following:
Any help would be greatly appreciated.
try with this code by changing as per youur requirment
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.crowd.embedded.api.User MutableIssue issue = issue ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() //to set user picker custom field CustomField customField = customFieldManager.getCustomFieldObjectByName("User to be terminated") User user=ComponentManager.getInstance().getUserUtil().getUser('User Name') issue.setCustomFieldValue(customField, user) //set components Project project = issue.getProjectObject() ProjectComponent component = componentManager.getProjectComponentManager().findByComponentName(project.getId(), "MyComponent") issue.setComponents([component.getGenericValue()]) //set description issue.setDescription("description");
don't forget to share if you get anything!!
I am getting the following error when I use this.
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script5.groovy: 17: unable to resolve class Project @ line 17, column 9. Project project = issue.getProjectObject() ^ Script5.groovy: 18: unable to resolve class ProjectComponent @ line 18, column 18. ProjectComponent component = componentManager.getProjectComponentManager().findByComponentName(project.getId(), "Google Account") ^ 2 errors
Thanks again for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add this two imports
import com.atlassian.jira.project.Project;
import com.atlassian.jira.bc.project.component.ProjectComponent;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same problem:
2013-09-06 11:13:22,728 http-bio-8080-exec-11 ERROR blah@uber.com 673x17451x1 1tskddq 127.0.0.1 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script8.groovy: 17: unable to resolve class Project @ line 17, column 9. Project project = issue.getProjectObject() ^ Script8.groovy: 18: unable to resolve class ProjectComponent @ line 18, column 18. ProjectComponent component = componentManager.getProjectComponentManager().findByComponentName(project.getId(), "Google Account") ^ 2 errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So after playing around for a while with this I ended up just using the component part of your code as I did not realize that @jamie's post function actually clones the custom field over anyways....
Thank you for your help.
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.
@Micah:
In order to assign the subtask based on the component lead, you need to set the project default assignee to the project/component lead. After this, you're good on the code that I give you
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.crowd.embedded.api.User com.atlassian.jira.user.util.UserUtil import com.atlassian.jira.project.Project; import com.atlassian.jira.bc.project.component.ProjectComponent; def componentManager = ComponentManager.getInstance(); def componentManager = ComponentManager.getInstance(); def customFieldManager = componentManager.getCustomFieldManager(); def issueFactory = componentManager.getIssueFactory(); def jiraAuthenticationContext = componentManager.getJiraAuthenticationContext(); def issueManager = componentManager.getIssueManager(); def indexManager = componentManager.getIndexManager() def public CreateSubtaskIssue (MutableIssue parentIssue, ProjectComponent newcomp) { //Creates Subtask MutableIssue newSubtask = issueFactory.getIssue(); //Gather the User to be terminated field and its value from the parent ticket def cfUtbt = customFieldManager.getCustomFieldObjectByName("User to be terminated"); def cfUtbtV = parentIssue.getCustomFieldValue(cfUtbtV) as User; // Taken from the parent ticket. //Here you can do a if statement in order to check whether the field value from the parent is empty or not def String username = cfUtbtV.getDisplayName(); // It will display name like Joe Doe or Jenny Jane // Subtask Summary Setting --->format: User to be terminated - Default Text newSubtask.summary = username + ": " + "Some default format"; //Wanna copy description from parent? No problem!!! newSubtask.description = parentIssue.description; //Set the component to the subtask. Did you say one component per subtask? def comps = [newcomp] as Collection <ProjectComponent>; newSubtask.componentObjects = comps; /*Set the subtasks assignee to the Component Owner. Note: At the project admin,set the project's default assignee to the project lead */ //Load and link the subtask to the parent ticket Map<String,Object> newIssueParams = ["issue":newSubtask] as Map<String,Object>; def currentUser = jiraAuthenticationContext.getUser() as User; GenericValue newSubtaskGV = issueManager.createIssue(currentUser,newIssueParams); //reindexing indexManager.reIndex(newSubtaskGV); //link the subtask with the parent issue subTaskManager.createSubTaskIssueLink(parentIssue, newSubtask, componentManager.getJiraAuthenticationContext().getUser()); } //At the parent ticket // Gather the current list of components set in the issue ticket. def componentList = issue.getComponentsObjects() as Collection<ProjectComponent> if (componentList != null ) { for(comp in componentList) { Create_Subtask(issue, component); //Create a subtask based and one component of the parent ticket goes to the subtask } }
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.
@Micah: Is the field User to be terminated is editable at the create issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
did you tried with in built function in script runner plugin
https://jamieechlin.atlassian.net/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Createasub-task
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As I mentioned above I am already trying to use exactly that method. I am having trouble with the code that is needed in the additional issue actions section of the post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What have you tried so far? Should be straightforward. But if you don't provide anything you have tried, it looks like you are asking people to do your work for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what is the field type of this "User to be terminated"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jamie: As I mentioned I do not know coding very well... so i have not really tried much. I looked around on the internet a little and tried using the script that was mentioned here:
https://answers.atlassian.com/questions/92882/set-component-in-groovy-script
but got the following in the logs:
2013-09-06 09:11:53,307 http-bio-8080-exec-23 ERROR blah@uber.com 551x16053x1 1oi0ks4 199.116.73.34,127.0.0.1 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script3
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script3 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111) ... 222 more Caused by: groovy.lang.MissingPropertyException: No such property: componentManager for class: Script3 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at Script3.run(Script3.groovy:16) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315) ... 223 more
@Rambanam: The field will be a user picker.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Rambanam: So I have spent some more time poking around and and looking at a lot of other examples of code to do things that are similar to what i am asking and have ended up with the following.... but I get a NPE.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.project.Project import com.atlassian.jira.bc.project.component.ProjectComponent MutableIssue issue = issue parent = issue.getParentObject() ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() //to set user picker custom field CustomField customField = customFieldManager.getCustomFieldObjectByName("Affected User") Object affectedUser = customField.getValue(parent) issue.setCustomFieldValue(customField, affectedUser) //set components Project project = issue.getProjectObject() ProjectComponent component = componentManager.getProjectComponentManager().findByComponentName(project.getId(), "Google Account") issue.setComponents([component.getGenericValue()]) //set description issue.setDescription("description");
Caused by: javax.script.ScriptException: java.lang.NullPointerException at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111) ... 230 more
Any ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.