Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Based on Resolution and Project name Create Issue in other Project using groovy

Rita YOUNES [Infosysta]
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.
December 28, 2015

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 ,

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 4, 2016

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

0 votes
Vasiliy Zverev
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.
December 28, 2015

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

Rita YOUNES [Infosysta]
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.
December 28, 2015

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,

Vasiliy Zverev
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.
December 28, 2015

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()"

Vasiliy Zverev
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.
December 28, 2015
Rita YOUNES [Infosysta]
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.
December 28, 2015

@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

Vasiliy Zverev
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.
December 30, 2015

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")

TAGS
AUG Leaders

Atlassian Community Events