Forums

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

Need to copy the custom field values from existing issue to newly created issues

A.Lakshmi Durga March 1, 2022

Hi,

I Need to copy the custom field values from existing issue to newly created issues only if I have selected same option in both the issues of select list custom field and both issues will have different issue types.

Example:

API Name is select list field. In that using one option " Agent Login" I have created one  issue and the issue type is New requirement.

Now I want to create another issue with Onboarding issue type and the API name is "Agent Login", this time newly created issue has to fetch the custom field values from existing issue i.e; New Requirement Issue type Issue.

Please let me know how to achieve this functionality in JIRA Server.

We are using Automation for JIRA and script runner addon's.

 

 Thanks for your help in advance!

 

Thanks,

Lakshmi.

 

 

 

2 answers

2 accepted

0 votes
Answer accepted
Sachin Dhamale
Community Champion
March 2, 2022

Issue issue = event.issue  // Newly created issue Object

def jqlSearch = /"/+type+/" ~ '/+issue.key+/'/     

//Define the JQL to find existing issue to match your criteria for ex ( issuetype != newly created issue and custom field = <select custom field value> 

//def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def userManager=ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName('jiraservice')
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
def issues=''
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = results.getResults()  // Existing Issue which match the criteria.

issues.each{foundIssue->    //Itrerate the issues
copyvalue(foundIssue, user, 10301L)   // call function to copy the value from existing issues to newly created issue
}


void copyvalue(Issue issue, def ApplicationUser user, Long eventId) {

//write code to take value from exiting issue and update to the newly created issue


}

 

This is the sample code which you need to modify like i mentioned.

Accept the answer if it helps

0 votes
Answer accepted
Sachin Dhamale
Community Champion
March 1, 2022

@A.Lakshmi Durga ,

 

Yes you can copy the values of custom field from other issues provided they have link between them.

If not then you need to write the custom script which will check the related issues based on the select list values and then copy the custom field value from that issue whenever new issue has been created (On  Create Listener)

A.Lakshmi Durga March 2, 2022

Hi @Sachin Dhamale ,

 

Can you please give a sample script for this.

 

Thanks,

Lakshmi

Suggest an answer

Log in or Sign up to answer