Hello,
Please I need help in writing groovy script .I want to use the code in a post function.
I have 8 Projects, for example when resolution is set to confirmed Bug and Project name is Project 1 :
I want to create a linked issue in Project 5 and issue time is a bug and If the project name is project 2 I want to create a linked issue(new issue) from the current to Project 6 and so one.
Any one can advise Please.
Thanks ,
Community moderators have prevented the ability to post new answers.
Hi Rita,
Looking at your requirements above it seems the easiest way to do this would be to use the built in Clones an Issue and Links post function provided by Script Runner. In order to do this you could place this post function on the transition in the workflow where the resolution gets set and configure it as shown in the screenshot below.
CloneandLink1.png
This will then clone the issue in the new project and link it back to the original issue as well as allowing you to update any fields required on the cloned issue. This post function can then be placed on each workflow where you need to create a linked issue inside another project.
I hope this helps.
Kristian
Here is a code example about issue creation. Tune it to your need:
Project curPrj = prjMng.getProjectObjByKey("Prj2"); if(curPrj == null) return "no this project" inputParameters.setProjectId(curPrj.getId()) .setIssueTypeId("10903") .setSummary("Summory") .setReporterId("vzverev") .setAssigneeId(curPrj.getLeadUserKey()) .setEnvironment("Enviroment") .setStatusId("6") .setPriorityId("2") .setDueDate(getDueDate(Integer.parseInt(getValue(splitedImpStr[0])))) .addCustomFieldValue(10807, getValue(splitedImpStr[2])); IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(curAppUser, inputParameters); ErrorCollection errorCollection = createValidationResult.getErrorCollection(); result = errorCollection.toString(); if(createValidationResult.isValid()){ IssueService.IssueResult createResult = issueService.create(curAppUser, createValidationResult); if(!createResult.isValid()) return "Bad" }
After issue creation you should use IssueLinkManager to create link between these issues ( https://docs.atlassian.com/jira/6.4.1/com/atlassian/jira/issue/link/IssueLinkManager.html)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
am a beginner in scrpting and I don't know very well how to put the resolution and to get the project name . Can you please help me. Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see. I assume that this code will be used into a postfunction. It means that you have predefined variable "issue" which represents current issue where you call the postfunction. 1) How to get project: for current issue use issue.getProjectObject(), to get project by code use "ComponentAccessor.getProjectManager().getProjectByCurrentKey("projectKey")" 2) To get project name use Project.getName() (https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/project/Project.html) 3) To set resolution add this to chain of sets: ".setResolutionId("id")". Find requared id. Also it is requared to set resolution date as "setResolutionDate()"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To speed up development see this: https://answers.atlassian.com/questions/32982259/is-there-a-simple-way-to-test-scriptrunner-postfunctions-conditions-and-validators
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Vasiliy Zverev can I use this ? if(issue.getProjectObject() == "Project 1" && Resolution== "Confirmed New Bug"){ log.warn ("Test succed"); newissue = issueFactory.getIssue() newissue.setSummary (issue.summary) string project1 = newissue.setProject (projectMgr.getProjectByName("App4legal")) newissue.setIssueType (issue.getIssueType()) newissue.description = issue.description newissue.reporter = issue.getReporter() params = ["issue":newissue] subTask = issueMgr.createIssue(currentUserObj, params) println subTask.get("key") linkMgr = ComponentManager.getInstance().getIssueLinkManager() linkMgr.createIssueLink (newissue.id, issue.id, project1,Long.valueOf(1), currentUserObj) } But how I can tell him to create issue in Project 5? Thanks 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.
I am not sure that your code will work, test it via ScriptConsole. To get a project by it's key you could use this: Project project = ComponentAccessor.getProjectManager().getProjectObjByKey("prjKey")
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.