Forums

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

Evaluation for single select custom field

Alexey Paveliev
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.
June 13, 2020

For a script to run I evaluate a complex condition for

1. a status equals 'Escalated'

2. a single select 'Reviewer needed?' equals 'Yes'

3. a single select 'Service Type' equals 'Email'

4. an Assignee is Empty - (I have not tried this so far, could use help tho)

 

I tried

cfValues['Reviewer needed?'].value == 'Yes'

cfValues['Reviewer needed?'].getValue() == 'Yes'

cfValues['Reviewer needed?'].getValue().contains('Yes')

with dozens of combinations of single and double quotes

And it fails with 

2020-06-13 10:30:30.802 ERROR - The condition: issue.status.name == "Escalated" && cfValues['Reviewer needed?']?.getValue() == "Yes" && cfValues['Service Type']?.getValue().Contains('Email')  evaluated to: ["Jira expression failed to parse: line 1, column 66:\n!, -, typeof, (, IDENTIFIER, null, true, false, NUMBER, STRING, new, [ or { expected, . encountered."]

I read thru many posts and documentation including this

https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/33030148/Built-In+Scripts#Built-InScripts-PowerAssertions

 

PS After moving evaluations to listener script body I got 

No such property: cfValues for class: Script1 on line 5

1 answer

1 accepted

0 votes
Answer accepted
Alexey Paveliev
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.
June 13, 2020

Non-numeric custom fields are not available and need to be got via REST calls

see example for two custom fields we use: Service Type and Reviewer Needed

//getting custom field names
def customFields = get("/rest/api/2/field")
   .asObject(List)
   .body
   .findAll { (it as Map).custom } as List<Map>

def cfServiceTypeId = customFields.find { it.name == 'Service Type' }?.id
def cfReviewerNeededId = customFields.find { it.name == 'Reviewer needed?' }?.id

//getting custom fields values
def result = get("/rest/api/2/issue/${issue.key}?fields")
   .header('Content-Type', 'application/json')
   .asObject(Map)
if (result.status == 200) {
   logger.info("Success getting fields")
   serviceType = result.body.fields[cfServiceTypeId]?.value
   reviewerNeeded = result.body.fields[cfReviewerNeededId]?.value
} else {
   logger.info("Error getting fields")
}

 

This does not work for service desk Request Type field though!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events