Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to link issue to project automatic with scriptrunner

Pablo Rodriguez
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 8, 2020

I would like to automatically create link issue to the parent project when is created or a script to get all issues and create the link.

//Import classes you need
import com.atlassian.jira.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.issue.fields.CustomField;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

// Get some additional information you typically need like current user
JiraAuthenticationContext userMgr = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser currentUserObj = userMgr.getLoggedInUser();

//Get an IssueManager. you always need one of those.
IssueManager issueMgr = ComponentAccessor.getIssueManager();
CustomFieldManager fieldmgr = ComponentAccessor.getCustomFieldManager();
MutableIssue issue = issueMgr.getIssueObject("TEST-2") // this is just an example key

//Print stuff. Just assuming you are playing around/learning in the Scriptrunner console.
log.error "";
log.error "The current user is " + currentUserObj.name;
log.error "The current issue ID is " + issue.id;
log.error "The current issue key is " + issue.key;
log.error "The current issue key is " + issue.getProjectId()

I have the issue.id and the projectId, But i don't know how connect.

Thanks

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
April 8, 2020

Have a look at https://library.adaptavist.com/entity/create-a-backdated-issue - it does some work with dates as well as creating an issue.

Suggest an answer

Log in or Sign up to answer