Forums

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

Scriptrunner

Javid Huseynli April 28, 2022

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
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 29, 2022

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

Javid Huseynli June 3, 2022

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events