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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

466 views 5 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you