Forums

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

Сopy the issue type to a custom field?

Evgeniy Lelei September 20, 2021

How do I copy name of issuetype in  custom field?

1 answer

0 votes
Martin Bayer [MoroSystems, s.r.o.]
Community Champion
September 20, 2021

Hi, it should be something like

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
import groovy.transform.Field

// ID of the field
final String customFieldId = "10101"
// the name of a 'text field' custom field
final String issueTypeName = issue.issueType.name


def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issueKey)

def issueInputParameters = issueService.newIssueInputParameters().with {
// set text fields
addCustomFieldValue(customFieldId, issueTypeName)
}


def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)
assert updateValidationResult.valid: updateValidationResult.errorCollection

def issueUpdateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, false)
assert issueUpdateResult.valid: issueUpdateResult.errorCollection

I used this snippet: https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console 

Evgeniy Lelei September 20, 2021

Thanks, but how do I do this using automation?

Martin Bayer [MoroSystems, s.r.o.]
Community Champion
September 20, 2021

Hi, you need to describe your usecase...you are on server...so you have scriptrunner installed? Do you have automation for jira App?

Evgeniy Lelei September 21, 2021

I have an installed version of the server, as well as installed automation, but no scriptrunner

Martin Bayer [MoroSystems, s.r.o.]
Community Champion
September 21, 2021

Ok you can use smartvalue {{issue.issueType.name}}. I just tested it and it works for Issue Created Trigger and Edit issue action. I tested it on Cloud so I hope it will be OK for Server/DC version:

Selection_388.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events