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,293,545
Community Members
 
Community Events
165
Community Groups

Scriptrunner

Hi. i want to change text custom field's string to other custom text field. I can do it with description (system field) field but cant do with custom field. i marked description where i wanna enter other custom field. Pls help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.plugin.webfragment.model.JiraHelper
import com.jirahelpers.JiraIssueParameterUtil
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.util.json.JSONObject
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.apache.log4j.*
import com.jirahelpers.JiraIssueParameterUtil
import com.jirahelpers.ProcessMatrixUtils
import com.jirahelpers.InsightObjectsUtils
import com.atlassian.jira.issue.customfields.manager.OptionsManager


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

def cField1 = customFieldManager.getCustomFieldObject("customfield_13237")
def cField2 = customFieldManager.getCustomFieldObject("customfield_13245")
def cFieldValue1 = issue.getCustomFieldValue(cField1)
def cFieldValue2 = issue.getCustomFieldValue(cField2)

final getCustomFieldValues1 = issue.getCustomFieldValue(cField1)
final getCustomFieldValues2 = issue.getCustomFieldValue(cField2)


issue.description.replace("branchname","$getCustomFieldValues1")

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Javid Huseynli

Looking at your code, I assume you are doing this from a Post-Function. 

You could try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager

def sampleEmail = customFieldManager.getCustomFieldObjectsByName('Sample Email').first()
def sampleEmailValue = issue.getCustomFieldValue(sampleEmail) as String

def textToList = customFieldManager.getCustomFieldObjectsByName('Text to List').first()
def textToListValue = issue.getCustomFieldValue(textToList) as String

issue.setCustomFieldValue(textToList, "${textToListValue} ${sampleEmailValue}".toString())

Please note that the sample code provided is not 100% exact to your environment. Hence, you will need to make the required modifications. 

Below are the screenshots of the Post-Function configuration:-

1) When creating the Post-Function select ScriptRunner's Custom script post-function as shown below:-

post_function_config1.png

2) Next, add the code as shown below.

post_function_config2.png

Next, save the config and publish the changes.

Below are a few test screenshots:-

1) Create a new issue and enter some values into the text fields as shown below and create the issue.

image1.png

2) Once the ticket is created, you will notice both the fields have their respective value, as shown below:-

image2_before_transition.png

image2_before_transition.png

image3_after_transition.png

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Thank you very much. Resolve that, i only need (.to String) 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Service Management

Jira Service Management Documentation Opportunities

Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...

200 views 0 5
Join discussion

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