So I've been working to add a post function to a workflow that will create a sub-task if condition is met in a specific cascading select custom field. I've placed a simple condition into the create a sub-task post function. However, upon testing of the post function in a test issue I'm receiving the following error:
java.util.NoSuchElementException: Cannot access first() element from an empty List
I don't have the exact code available at this time but it follows the structure shown in the ScriptRunner snippets drop down and contains multiple or (" || ") operators to cover all of the field combinations being looked for, so it's like this:
cfValues['Field Name 1']?.values()*.value == ['Parent','Child'] || cfValues['Field Name 2']?.values()*.value == ['Parent','Child'] || cfValues['Field Name 3']?.values()*.value == ['Parent','Child'] ||...continuing for multiple custom fields
Any assistance with this would be greatly appreciated, thanks.
The code snippet doesn't appear to be correct.
In the validator, the cfValues function implicitly extracts the values from the field. So when you use
cfValues['Field Name 1']
it is equivalent to using
def customFieldManager = ComponentAccessor.customFieldManager
def field1 = customFieldManager.getCustomFieldObjectsByName('Field Name 1').first()
def field1Value = issue.getCustomFieldValue(field1)
So, there is no need to call an additional values() method from it as you have done:-
cfValues['Field Name 1']?.values()*.value == ['Parent','Child']
You can instead use
cfValues['Field Name 1'] in ['Parent','Child'] || cfValues['Field Name 2'] in ['Parent','Child'] || cfValues['Field Name 3'] in ['Parent','Child']
Also, what type of validator are you using? Is it the Simple Scripted Validator or the Custom Scripted Validator?
I am looking forward to your clarification.
Thank you and Kind regards,
Ram
Hello @Ram Kumar Aravindakshan _Adaptavist_ and thank you for the assistance. My apologies for my original post not being as clear (I've cleared that up in an edit). The script is being used as the condition for a ScriptRunner Creat a sub-task post function.
Your suggested updates to use "in" instead of values() did clean up the errors. However, even though there aren't any errors, I'm not seeing the creation of the sub-task or any errors in the atlassian-jira.log. Any thoughts as to what may be occurring here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since you are using the Post-Function, could you please clarify if you are using the Create sub-task [ScriptRunner] or a Custom script post-function [ScriptRunner]?
If it is the former, please share a screenshot of your configuration and if there are additional conditions to your code, kindly include them as well. If it is the latter, share your code.
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.
Hi @Ram Kumar Aravindakshan _Adaptavist_
I'm using the Create sub-task [ScriptRunner] functionality for the post function.Though I'm unable to provide a screenshot I will transcribe the 8 Post Functions that are present (the first 5 being the automatic system post functions).
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.