You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hey all,
I have a post-function that creates a sub-task whenever a specific sub-task resolves. I wish to add a condition based on a custom field, but I am not succeeding.
def cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_id")
def cfv1 = issue.getCustomFieldValue(cf1)
if (issue.isSubTask() &&
issue.summary.contains("text") &&
cfv1 == "Yes")
Above doesn't result in errors, but neither results in a created sub-task when the value is Yes. Logs are also empty.
I've also tried:
issue.customfield_11301 == "Yes"
[Static type checking] - No such property: customfield_11301 for class: com.atlassian.jira.issue.MutableIssue
What am I missing here?
Thanks in advance.
Hi Marc,
My first question is probably not the problem - you've got "customfield_id" in the "def cf1" line. Do you mean that? If customfield_id is a variable you've set earlier, it shouldn't be in quotes. If it's a direct name, then shouldn't it be "customfield_11301"?
If that's not the problem, then the next question is "what type of field is 11301"? If it's a string, and the field contains exactly "Yes", then your code should be working. But if it's a select list then the content you get back from getCustomFieldValue() won't be a string - it will be an option object.
If it is an option-type field then you can use cfv1.getName() to get the display name of the option (which will be the "Yes" you can compare with another string)
(Oh, and if it's a multi-select type field, you'll get an array of options)
Haha that's just me failing at censoring. It is actually
def cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11301")
Like you said.
The field is a Select List (single choice).
If I change it to cfv1.getName() I get the following error:
Cannot find matching method com.atlassian.jira.issue.customfields.option.Option#getName(java.lang.String). Please check if the declared type is correct and if the method exists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
:-)
We can't tell much from customfield_12345 - it's vanishingly rare that two systems will use the same id for a user-created custom field that have the same type and name! (Except when you clone a system, which would be within your organisation and for doing development, testing, migration or upgrades)
Anyway, that means the problem is the fetch of the data from it. And I've mislead you.
getName() works in a lot of places in Jira, but when it does not, getValue() will. I can never remember which one works where!
Apologies for that!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot, final result which is working:
def cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_id")
def cfv1 = issue.getCustomFieldValue(cf1)
if (issue.isSubTask()
&& issue.summary.contains("text")
&& cfv1.getValue() == "Yes"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great! Thanks for letting us know you got it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.