Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,082
Community Members
 
Community Events
168
Community Groups

Groovy Script postfunction Function

Edited

Hello everybody.

I have created a script to find the value of the epic link field and add it to a new field. The script does not give me an error but it appends the object value of the "epic link" field in the new field

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def checkLink = {link -> false}
def cFieldLinkEpica = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}

def cFieldEpicaAux = customFieldManager.getCustomFieldObject('customfield_13501')
issue.setCustomFieldValue(cFieldEpicaAux, cFieldLinkEpica)

The script I need is the following:

1. Let him check the type of problem.
2. Let him get the value of the "Epic Link" field for that problem.
3. If it is a subtask, find the value in the parent task of that subtask.
3. Add the value of the "epic link" field to the newly created field.

1 answer

1 accepted

Hola,

Puede seguir el siguiente ejemplo. Debería funcionar para ti.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager

def issueManager = ComponentAccessor.issueManager
def mutableIssue = issue as MutableIssue

def
customFieldManagerPackges = ComponentAccessor.getCustomFieldManager()
def cFieldPackges = customFieldManagerPackges.getCustomFieldObject("customfield_12001")
def cFieldValuePackges = issue.getCustomFieldValue(cFieldPackges)

String
selectedUser;

//Get current logged-in user for issue update after setting the assignee
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

switch
(cFieldValuePackges) {
case "traful_dev_users":
selectedUser
= "wuedva07";
break;

case
"traful_infra_users":
selectedUser
= "wuedva07";
break;
}

//Set assignee & update issue
UserManager userMgr = ComponentAccessor.getUserManager()
ApplicationUser userName = userMgr.getUserByName(selectedUser)

issue
.setAssignee(userName)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

Espero que esta información te ayude!

Sí está respuesta respondió a su pregunta, por favor márquela como la respuesta aceptada.

Hello everybody.

I have created a script to find the value of the epic link field and add it to a new field. The script does not give me an error but it appends the object value of the "epic link" field in the new field

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def checkLink = {link -> false}
def cFieldLinkEpica = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}

def cFieldEpicaAux = customFieldManager.getCustomFieldObject('customfield_13501')
issue.setCustomFieldValue(cFieldEpicaAux, cFieldLinkEpica)

The script I need is the following:

1. Let him check the type of problem.
2. Let him get the value of the "Epic Link" field for that problem.
3. If it is a subtask, find the value in the parent task of that subtask.
3. Add the value of the "epic link" field to the newly created field.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS

Atlassian Community Events