Forums

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

How to change this script from subtask to linked issue

Vahagn Beglaryan October 25, 2021

Hi there, 

 

We need to change this script. Now it creates sub-tasks, we need to change it to standard issue-type, with "connects" link type.

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def lstCmp = issue.components.name

 


def cfRIA = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("YYYYY")

Collection<ApplicationUser> users= (Collection) issue.getCustomFieldValue(cfRIA);

if(users != null && lstCmp.contains("testtest"))
{

for(i in 0..users.size()-1)
{
Object AssigneeValue = "Mr.Test";

issueObject = ComponentAccessor.getIssueFactory().getIssue()
issueObject.setProjectObject(issue.getProjectObject())
issueObject.setIssueTypeId("XXXXX")
issueObject.setParentId(issue.getId())
issueObject.setReporter(issue.getReporter())


issueObject.setSummary(issue.getSummary() + ' ' + users.get(i).getValue())
issueObject.setAssigneeId(AssigneeValue)
issueObject.setDescription(issue.getDescription())

def issueManager = ComponentAccessor.getIssueManager()
def subTask = issueManager.createIssueObject(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issueObject)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(issue, subTask, ComponentAccessor.jiraAuthenticationContext.getLoggedInUser())
i++
}

}

 

Thanks in advance.

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.
October 25, 2021

Ok, the easy bit is obviously just to change the "set issue type id" to create an issue instead of a sub-task type.

Then instead of the sub-task linking, you can have a look through https://library.adaptavist.com/entity/add-or-update-the-issue-link-for-an-issue-in-jira to see how to work with issue-links.

Vahagn Beglaryan October 25, 2021

Thanks a lot, could you please correct my code and paste it again. It would be great.

Suggest an answer

Log in or Sign up to answer