Script Runner Create Sub-Task Condition Code Issues

Glenn Edwards July 13, 2022

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.

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 14, 2022

Hi @Glenn Edwards

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 

Glenn Edwards July 14, 2022

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?

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 14, 2022

Hi @Glenn Edwards

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

Glenn Edwards July 15, 2022

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).

 

  1. Set issue status to the linked status of the destination workflow step.
  2. Add a comment to an issue if one is entered during a transition.
  3. Update change history for an issue and store the issue in the database.
  4. Re-index an issue to keep indexes in sync with the database.
  5. Fire a Issue Resolved event that can be processed by the listeners.
  6. Update Any Issue Field (JSU)
    • Issue Field: Jump to Resolve
    • Field Value: 14604
  7. Create a sub-task: Sub-task will be created with issue type: Sub-task (condition applies)
  8. Fast-track transition an issue: Action: Custom Field (131) will be applied. Note that this should go after the Fire Event function.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events