Forums

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

Copy the Environment field to a scripted field

Whitni Smith
Contributor
June 10, 2019

I've been unable to find information on how exactly to copy the Environment field to a scripted text field that will be available in our reporting tool.

The issue lies in that the Environment field isn't exactly a "custom field type" so def cfType as cf.getCustomFieldType() doesn't work and I don't have a solution.

This is what I have, from using an actual custom field but it won't work for the Environment field, which I am setting using an automation rule based on summary information or request-channel-type.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def FIELD_NAME = "Environment"

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName(FIELD_NAME)
def cfType = cf.getCustomFieldType()
def requestType = issue.getCustomFieldValue(cf)

 

I need to modify the code above to work with the system field, Environment and copy the text contents of that field into a custom-field, Environment-scripted

 

1 answer

1 accepted

1 vote
Answer accepted
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.
June 10, 2019

I suspect by "Environment field", you mean the system Environment field, not a custom field.

The system field is text, so you don't need the .getName(), but also the field belongs to issues, not request types.  So I don't know what you're intending to do with a request type here.

The value of the environment field in a scripted field is just (from memory)

return issue.getEnvironment()

Whitni Smith
Contributor
June 10, 2019

Hi Nic,

Correct, Environment field as in the system Environment field not a custom field, we are setting it through an automation rule based on the field request-channel-type or a set of other conditions but it itself is the system Environment field.

I'm not wanting to do anything with a request type, I just want to copy the text in the Environment field to a custom field, let's call it Environment-scripted, so that it can be queried in our reporting tool, the current system field, Environment, isn't available.

Whitni Smith
Contributor
June 10, 2019

I am accepting @Nic Brough -Adaptavist- answer because oddly enough, the only code I needed in the scripted field was he provided -

issue.getEnvironment()

 

Making something so simply, complicated.

Suggest an answer

Log in or Sign up to answer