Condition in a Script Fragment with a customfield of the current issue

Pascal MALFOY March 22, 2019

Hello,

I want to create a condition in a Script Fragment : "Constrained create issue" with a customfield value of the current issue and it doesn't work :

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fist = customFieldManager.getCustomFieldObjectByName("FIST")
fist == "FIST avec attente"

Please, how can I do that

 

Best regards,

Pascal Malfoy

1 answer

1 accepted

1 vote
Answer accepted
Joanna Choules
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.
April 4, 2019

Hi Pascal,

getCustomFieldObjectByName simply fetches an object representing the custom field itself (i.e. the thing you see when you go to Administration > Issues > Custom fields). To get the value of a custom field for a specific object, you then need to use getCustomFieldValue:

issue.getCustomFieldValue(fist) == "FIST avec attente"

This replaces the final line of your current script: the rest of the code stays the same.

Yours,

Joanna Choules, Atlassian Product Support

Pascal MALFOY April 4, 2019

Thanks a lot Joanna,

the syntax is well and accepted by the fragment verification but it seems not to work.

I forgot to precise the customfield is a Select list (Single choice) type and I think it is the problem.

What do you think and what it the new syntax ?

Thanks again for your response and your reactivity,

Pascal

Joanna Choules
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.
April 4, 2019

Hi Pascal,

In that case you would want to use issue.getCustomFieldValue(fist).value. Note that the static type checker will flag this as a problem because it cannot be sure ahead of time that the result of getCustomFieldValue will have a value property, but there should be no problems when the code actually runs.

Joanna

Pascal MALFOY April 4, 2019

Hi Joanna,

It works now.

Thank you very much

Best regards,

Pascal

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events