copy field value from one field to another within same issue

Varun Joseph Allu September 12, 2022

Hi All,

We have a requirement to copy field value from Summary to Ticket Summary (Text field) and Description to Ticket Description (Text Field ) .

Can some one help with the listner script to achive.

your inputs are highly appreciated.

 

Thank you,

Varun

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 13, 2022

Hi @Varun Joseph Allu

For your requirement, you can try something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue

def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def sampleTextField = customFieldManager.getCustomFieldObjectsByName('Sample Text Field').first()
def sampleMultiLineText = customFieldManager.getCustomFieldObjectsByName('Sample Multi Line Text').first()

def description = issue.description
def summary = issue.summary

if (summary && description) {
issue.setCustomFieldValue(sampleTextField, summary)
issue.setCustomFieldValue(sampleMultiLineText, description)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

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

Below is a screenshot of the Listener Configuration:-

 listener_config.png

Below are a few test screenshots for your reference:-

1. First, when creating a new issue, only the values for the Summary and Description fields are entered.

test1.png

2. Once the issue has been created, as expected, the values from the Summary and Description fields are copied to the Sample Text Field and Sample Multi Line Text field accordingly, as shown in the screenshot below:-

test2.png

3. If the Summary field is updated, the Sample Text Field is updated accordingly, as shown in the screenshots below:-

test3.pngtest4.png

4. Similarly, if the Description field is updated, the Sample Multi Line Text field is updated accordingly, as shown below:-

test5.png

 

I hope this helps to solve your question. :)

 

Thank you and Kind regards,

Ram

Varun Joseph Allu September 14, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_  ,

 

Thanks for the script,
It is working as expected.
Thank a lot for your support.

 

Regards,
Varun

Pratibha Tambakad January 5, 2024

Hello Ram,

 

Does this works for Select list field also?

I have requirement where values entered in the one single select list should be displayed in another field select list field..

We have created Database picker field to achieve this. is it possible to do it using only normal scripted field or behaviour?

Find the configuration script below:

 

import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.canned.jira.fields.editable.database.SqlWithParametes

getSearchSql = { String inputValue, Issue issue, String originalValue ->
    // return SqlWithParameters, that will control the search SQL..., eg:
    new SqlWithParameters("""
        select customfieldoption.customvalue, customfieldoption.customvalue as customvalue2 from customfieldoption
        left join configurationcontext
        on customfieldoption.customfieldconfig = configurationcontext.fieldconfigscheme
        where customfieldoption.customfield=10400
        and configurationcontext.project=?
        and lower(customfieldoption.customvalue) like  '%' || lower(?) || '%'   and  customfieldoption.disabled = 'N' order by customfieldoption.customvalue asc
    """, [issue.projectId, inputValue])
}

getValidationSql = { String id, Issue issue, String originalValue ->
    // return SqlWithParameters, that will control the validation SQL..., eg:
    new SqlWithParameters("""
        select customfieldoption.customvalue, customfieldoption.customvalue as customvalue2 from customfieldoption
        left join configurationcontext
        on customfieldoption.customfieldconfig = configurationcontext.fieldconfigscheme
        where customfieldoption.customfield=10400
        and configurationcontext.project=?
        and customfieldoption.customvalue = ?
    """, [issue.projectId, id])
}
Database picker screenshot.PNG
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 5, 2024

Hi @Pratibha Tambakad

It's not the same for the Database Picker.

You can use the Behaviour to update the field based on the option selected from the DB Picker. Still, you will need to do some filtration, i.e. pull the value displayed in the DB Picker, query it via SQL and put the result in the destination field.

I suggest you take a look at this Adaptavist Library example for more information.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer