You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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")
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:-
2) Next, add the code as shown below.
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.
2) Once the ticket is created, you will notice both the fields have their respective value, as shown below:-
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.