I have this script but I want to customize it as per the requirement below-

Hello,

I have this script but I want to customize it as per the requirement below-

I want that if my issue (for example ABC-103 is having the issue rank- 5) is moved/transitioned to production then the issue (whichever it is with issue rank -6 ) should change its value from 6 to 5.

similarly, if an issue ABC-110 (any random issue) moves to production with an issue rank say -10 the issue with issue rank -11 must change its issue rank to 10.

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

String String = “Select List”;
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager CustomFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = CustomFieldManager.getCustomFieldObjectByName(String);

def availableOptions = ComponentAccessor.optionsManager.getOptions(cf.getRelevantConfig(issue))

// find the custom field option valuedef currValue = availableOptions.find { it == issue.getCustomFieldValue(cf) }

// convert the option value to a long data typedef optionValue = Long.valueOf(currValue.toString())

// decrement the valueLong newValue = optionValue-1;

// find the option value that match the decrement valuedef optionToSet = availableOptions.find { it.toString() == newValue.toString() }

// update the new option if foundif(optionToSet)
{
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf),optionToSet), changeHolder);
}

in short-

  • ABC-2 (rank = 1)
  • ABC-4 (rank = 2)
  • ABC-3 (rank = 3)
  • ABC-1 (rank = 4)
  • ABC-5 (rank = 5)
  • ABC-6 (rank = 6)
  • ABC-7 (rank = null)

When ABC-1 goes to production, list is changed to

  • ABC-2 (rank = 1)
  • ABC-4 (rank = 2)
  • ABC-3 (rank = 3)
  • ABC-5 (rank = 4)
  • ABC-6 (rank = 5)
  • ABC-7 (rank = null)
  • ABC-1 (rank = null)