Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


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
Community Members
Community Events
Community Groups

How to copy only new values from field to field?

Hello, got very specific use case and finding a lot of dead ends. 

I got two insight field, multi object field.

Lets say we have SourceField and TargetField.

The SourceField is present on transition screen.

The TargetField is hidden, just field for the logic behind. 

What I need is:

When I execute the transition, the SourceField already contain object(s). 

After I execute the transition I need to copy the objects into the TargetField, but only the new added values, during the transition. 

Cannot use the TargetField, as it is handled and updated by another scripted logic behind and could be even empty. 

Was thinking about originalIssue, but it doesnt work for me.

Any ideas?

Cheers, Tom

1 answer

Here is my code I trying currently to run:

The general target is approval process, where manager can edit pending persons (represented by insight objects) by both add new and remove.

When adding, user or group should appear in PENDING field.

When removing, user or group should disappear from all PENDING, APPROVED and DECLINED. 

Its quite complex, but generally, what we need is:

Source Field have value [PERSON A]

During transition you will add to that custom field also PERSON B, so during transition it will look like [PERSON A, PERSON B]

When we need, that only PERSON B will be copied to the Target Field

What we have, it that both PERSON A and PERSON B are copied to Target Field.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.ModifiedValue;

def members = []

Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()

//--------------------------- MAIN ELEMENT DEFINITION ------
def fawi = issue.get("customfield_18201") // 1st approval wave individuals BUFFER
def fawiP = issue.get("customfield_18207") // 1st approval wave individuals Pending
def fawiA = issue.get("customfield_18209") // 1st approval wave individuals Approved
def fawiD = issue.get("customfield_18208") // 1st approval wave individuals Declined

def fawg = issue.get("customfield_18200") // 1st approval wave groups BUFFER
def fawgP = issue.get("customfield_18204") // 1st approval wave groups Pending
def fawgA = issue.get("customfield_18205") // 1st approval wave groups Approved
def fawgD = issue.get("customfield_18206") // 1st approval wave groups Declined

def sawi = issue.get("customfield_18203") // 2nd approval wave individuals BUFFER
def sawiP = issue.get("customfield_18213") // 2nd approval wave individuals Pending
def sawiA = issue.get("customfield_18214") // 2nd approval wave individuals Approved
def sawiD = issue.get("customfield_18215") // 2nd approval wave individuals Declined

def sawg = issue.get("customfield_18202") // 2nd approval wave groups BUFFER
def sawgP = issue.get("customfield_18210") // 2nd approval wave groups Pending
def sawgA = issue.get("customfield_18211") // 2nd approval wave groups Approved
def sawgD = issue.get("customfield_18212") // 2nd approval wave groups Declined

def sawiAcf = customFieldManager.getCustomFieldObject("customfield_18214")
def sawiDcf = customFieldManager.getCustomFieldObject("customfield_18215")
def sawiPcf = customFieldManager.getCustomFieldObject("customfield_18213")

def fawiAcf = customFieldManager.getCustomFieldObject("customfield_18209")
def fawiDcf = customFieldManager.getCustomFieldObject("customfield_18208")
def fawiPcf = customFieldManager.getCustomFieldObject("customfield_18207")

def sawgAcf = customFieldManager.getCustomFieldObject("customfield_18211")
def sawgDcf = customFieldManager.getCustomFieldObject("customfield_18212")
def sawgPcf = customFieldManager.getCustomFieldObject("customfield_18210")

def fawgAcf = customFieldManager.getCustomFieldObject("customfield_18205")
def fawgDcf = customFieldManager.getCustomFieldObject("customfield_18206")
def fawgPcf = customFieldManager.getCustomFieldObject("customfield_18204")

members = []
members = [fawgP,fawgA,fawgD].flatten()  // Loading all decision makers
members = members.findAll()   

if (members == []) {members = null}
if (members){
  if (!(members?.sort() == fawg?.sort())) {  // Sort 
    if (fawg) {members = members?.minus(fawg)}  // Looking for removed decision makers
  fawgP?.removeAll(members)  // Removing removed DM

if (fawgA == []) {fawgA = null}
fawgAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgAcf), fawgA), changeHolder);  
if (fawgD == []) {fawgD = null}
fawgDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgDcf), fawgD), changeHolder);   
if (fawgP == []) {fawgP = null}
fawgPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawgPcf), fawgP), changeHolder);     // zapísanie výsledkov späť do decision polí

members = []
members = [fawiP,fawiA,fawiD].flatten()
members = members.findAll()

if (members == []) {members = null}
if (members) {
  if (!(members?.sort() == fawi?.sort())) {
    if (fawi) {members = members?.minus(fawi)}

if (fawiA == []) {fawiA = null}
fawiAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiAcf), fawiA), changeHolder);  
if (fawiD == []) {fawiD = null}
fawiDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiDcf), fawiD), changeHolder);   
if (fawiP == []) {fawiP = null}
fawiPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fawiPcf), fawiP), changeHolder);   

members = []
members = [sawiP,sawiA,sawiD].flatten()     
members = members.findAll()       

if (members == []) {members = null}
if (members){
  if (!(members?.sort() == sawi?.sort())) {   
    if (sawi) {members = members?.minus(sawi)}  


if (sawiA == []) {sawiA = null}
sawiAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiAcf), sawiA), changeHolder);   
if (sawiD == []) {sawiD = null}
sawiDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiDcf), sawiD), changeHolder);  
if (sawiP == []) {sawiP = null}
sawiPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawiPcf), sawiP), changeHolder);  

members = []
members = [sawgP,sawgA,sawgD].flatten()
members = members.findAll()

if (members == []) {members = null}
if (members){
  if (!(members?.sort() == sawg?.sort())) {
    if (sawg) {members = members?.minus(sawg)}

if (sawgA == []) {sawgA = null}
sawgAcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgAcf), sawgA), changeHolder);   
if (sawgD == []) {sawgD = null}
sawgDcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgDcf), sawgD), changeHolder);  
if (sawgP == []) {sawgP = null}
sawgPcf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sawgPcf), sawgP), changeHolder);  

Maybe @David Fischer _Appfire_ ? Any ideas? I tried also JMWE copy field to field with append only new values, but did not get expected results. 

David Fischer _Appfire_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 18, 2021

Hi @Tomáš Vrabec ,

first of all, if you're running this code inside a Scripted (Groovy) post-function, you should use JMWE's simplified API, especially when writing to the field (using the {{issue.setFieldValue}} method).

As for helping you, you'd need to post a minimal script that focuses on the problem at hand (identifying changes to the source field) instead of your long and complicated script... However, I don't actually see how you could get the previous value of your Insight custom field. Did you try using the issue history, and moving the post-function to the bottom of the list? Maybe Insight will write an entry in the issue history for its field, and you can thus see the change made by the user (between "from" and "to")? To access the issue history, you can use issue.getFieldHistory()

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events