Need to add customised label if a custom field has value

Naveen kumar November 26, 2024

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

4 answers

2 votes
Shiva Kumar Hiremath
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2024

Hello Naveen,

Jira automation is free and its available Jira cloud,let me know whether you are using JIra Data center or cloud.


Thanks
shivakumar

Naveen kumar November 27, 2024

Jira Data center

0 votes
Naveen kumar November 27, 2024
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

 

@BaseScript FieldBehaviours fieldBehaviours
def customFieldA = getFieldById("customfield_25202")  
def customFieldValue = customFieldA.getValue()

 

def labelsField = getFieldByName("Labels")
if (customFieldValue ) {
   
    labelsField.setFormValue(['Incident']) 
} else {
    
    labelsField.setFormValue(['No_incident']) 
}
This script is not working , not sure where it went wrong
0 votes
Shiva Kumar Hiremath
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2024

Hello Naveen,

You can achieve that using Automation,something similar like Trigger>>>Field Value changed
>>>select the field     Action>> Edit issue     label.png

0 votes
Bharat Kalia
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 26, 2024

Hey @Naveen kumar - Have you tried doing it via an automation rule? just curious if the script is actually needed or not. 

Thanks,

Naveen kumar November 27, 2024

we dont have automation plugin to achieve it, we currently have scriptrunner.

Suggest an answer

Log in or Sign up to answer