I wanted to use the value of a customfield as a condition

I have a custom field called "Approval Needed". And within that customfield there are 5 different values.

 

-Immediate Execution

-Normal

-Execute Tonight

-None

-Execute before next CCB

 

I have been trying to figure out, with no success, how to condition scriptrunner custom email listiener, to only fire when the value of that custom field (Approval Needed), equals 1 or more of those values. I am not great at groovy. but all i can seem to figure out is:

 

getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approval Needed"))

 

    def approvalNeeded = getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approval Needed"))

 

Which is passing (i think?) the value of Approval needed into the variable "approvalNeeded"

 

I could use a littel help with the rest of this condition..

1 answer

This widget could not be displayed.
Mahesh S Community Champion Sep 27, 2016

Please use this as a reference.

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField approvalNeeded = customFieldManager.getCustomFieldObjectByName("Approval Needed")
 
String value = (String) issue.getCustomFieldValue(approvalNeeded)

Now, the value of Approval needed into the variable 'value' and go ahead with further coding as you required.

Here's the same script, with imports and more relaxed typing:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def approvalNeeded = customFieldManager.getCustomFieldObjectByName("Approval Needed")
def value = issue.getCustomFieldValue(approvalNeeded)

See also the examples using the OptionsManager to show you how to get the list of possible values for your select list field. https://scriptrunner.adaptavist.com/4.3.7/jira/recipes/behaviours/select-list-other.html. You probably won't need them for your use case, but you may for similar work.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

564 views 25 15
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you