I have created a scripted custom field and if the field is not empty i want Incident to be added as label in the ticket along with other labels and if its empty i want No_Incident to be added in the ticket. I have tried my best to create the script using behaviours but none of them works. can you helpme with the script please. I have script runner and dont have jira automation plugin.
script:
I don't know what you're seeing when you run the code but I'd change it as below to update labels without overwriting existing ones.
def customFieldA = getFieldById("customfield_25202")
def labelsField = getFieldByName("Labels")
def customFieldValue = customFieldA.getValue()
def existingLabels = labelsField.getValue() as List ?: []
if (customFieldValue) {
if (!existingLabels.contains('Incident')) {
existingLabels.add('Incident')
}
// Remove 'No_incident' if present
existingLabels.remove('No_incident')
} else {
if (!existingLabels.contains('No_incident')) {
existingLabels.add('No_incident')
}
// Remove 'Incident' if present
existingLabels.remove('Incident')
}
labelsField.setFormValue(existingLabels)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.