Skip to end of banner
Go to start of banner

Copy value from one custom filed to another when the value of the first custom field is changed

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

This script runs as a listener to the issue update event. Should the value of the Color field (customfield_10712) change from the previous value the script will update the custom field called Color 2 (customfield_10717).

Updated Script

struct _history {
  date changeDate;
  string value;
}

_history h = fieldHistory(key, "customfield_10712");
int hCount = arraySize(h);

if(hCount >= 3 ) {   
     if((h[hCount - 1] != h[hCount - 3]) || hCount == 3) {
        %key%.customfield_10717 = %key%.customfield_10712;
    }
}

Old Script

//gets the history of the Color custom field
string [] h = fieldHistory(key, "customfield_10712");
int hCount = arraySize(h); //get the size of the history array

//If the value of the field is null the array size (hCount) will be 0
//If the value has been set only 1 time the array size (hCount) will equal 3
//If the value has been set more than once the array size (hCount) will be greater than 3
if(hCount >= 3 ) {
    
    //If the value in history has changed OR the value was only set once
    if((h[hCount - 1] != h[hCount - 3]) || hCount == 3) {
        %key%.customfield_10717 = %key%.customfield_10712;
    }
}
  • No labels