I want to create a listener so when a custom field is updated the value is converting to lowercase.
How can I accomplish this?
Hi @Julia
For your requirement, you can try something like this:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issue = event.issue as MutableIssue
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def sampleText = customFieldManager.getCustomFieldObjectsByName('Sample Text').first()
issue.setCustomFieldValue(sampleText, sampleText.getValue(issue).toString().toLowerCase())
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Listener configuration:-
Since you mentioned in your description that you want this to trigger only when the field is updated, only the IssueUpdate event has been added.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.