Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to auto assign a label based on a custom field value

Anuj Balaji February 15, 2021

HI,

I have a custom field called "Is Change Required?" which has "Yes" and "No" as options. If the response is "Yes" I would like to automatically assign the label "ChangeRequired" to the ticket. The question is on a request through a Service Desk Portal. 

How do I do this using either a postfunction or a behaviour?

I am on Jira Data Center so I do not have access to the Autonation Plugin unfortunately. 

2 answers

0 votes
Daniel Ebers
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.
February 16, 2021

Hi @Anuj Balaji
I am not sure about the Service Desk Portal-part but for a postfunction in a workflow using Script Runner it works fine in my tests like this (Groovy):

import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()


CustomField radioButton = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Change");

if(radioButton == null)
return false

if(radioButton.getValue(issue).toString().equals("yes"))
{
LabelManager mgr = ComponentAccessor.getComponent(LabelManager.class)
mgr.addLabel(user, issue.id, 'ChangeRequired', false)
}
else
{
return false
}


As soon as the issue has the value "yes" for the Custom Field "change" a label is set during a transition of your choise using a post function.

You might need to tweak it a bit for Custom Field names and possible further requirements that might come up in future - the above one is pretty basic.

Regards,
Daniel

0 votes
Pramodh M
Community Champion
February 15, 2021

Hi @Anuj Balaji 

Install Automation of Jira Lite and have automation work done for you!

You can set the automation as follows,

If the custom field is changed, you can edit the label field.

Thanks,
Pramodh

Anuj Balaji February 15, 2021

Hi @Pramodh M : Thanks for responding. Like I said, unfortunately, Automation for Server Lite does not work on Data Center. 

Pramodh M
Community Champion
February 15, 2021

Apologies didn't see the last sentence!

Anuj Balaji February 15, 2021

Thank you @Pramodh M - I was hoping to exhaust all my options with Scriptrunner before having to spend the money on the Plugin.

Pramodh M
Community Champion
February 15, 2021

Hi @Anuj Balaji 

Please accept the answer!

Thanks,

Pramodh

Anuj Balaji February 15, 2021

I would still like to keep this open for other potential solutions

Pramodh M
Community Champion
February 15, 2021

I'm waiting! to see best solution 😎

Suggest an answer

Log in or Sign up to answer