Check/uncheck Checklist options (okapya) with ScriptRunner behavior

Alfira Merinova September 22, 2023

Hello, In Jira Server/Data Center we have Checklist plugin installed (okapya). We have a lot of automation based on ScriptRunner/Groovy: make custom fields read-only or hidden, select value or add new options into the select list custom field based on the value in the other custom field.

We also need possibility to manage Checklist behavior with help of ScriptRunner Behaviours on Create/Edit Screens.

Currently request which I got is very simple:

  1. Set several Checklist options "checked" based on the other custom field value on Create/Edit Screen.
  2. Also I need to make Checklist field read-only or writable based on the value of the other custom field on Create/Edit screen.
  3. Another request is to make all options in Checklist read-only except one particular option on Create/Edit screen.

I tried just simple case: created ScriptRunner Behavior to make Checklist field read-only, but it didn't work - checklist is still editable and I can check/uncheck options.

Behavior.PNG

Some quick server-side script I tried in ScriptRunner Behavior for the Checklist custom field:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*
import com.okapya.jira.checklist.*

def checklistField = getFieldById(fieldChanged)

Collection<ChecklistItem> items = (Collection<ChecklistItem>) checkboxField.value
items.find(item -> item.getName() == "Help").setChecked(true)

But it doesn't work as well - fails with cast error:

Cannot cast object '{"name":"Help","checked":false,"mandatory":false,"globalItemId":56712,"statusId":"none","rank":6,"id":7,"dueDate":null,"isHeader":false,"priorityId":null,"assigneeIds":[],"version":"5.0","linkedIssueKey":null}' with class 'java.lang.String' to class 'java.util.Collection'
at 0e54872ceb9b5a6e59e4cdcbcb9a102e.run(0e54872ceb9b5a6e59e4cdcbcb9a102e.groovy:8)

I went through the Checklist documentation https://okapya.atlassian.net/wiki/spaces/CHKDOC5/pages/3236659321/Getting+started+with+ScriptRunner and didn't find solutions to manage behavior of the Checklist on Create/Edit screen.

If you have good examples or documentation for my cases, please share.

Thanks in advance.


Checked in 2 different envs:

First instance:

Jira: v9.4.9

ScriptRunner: 8.9.0

Checklist: 6.2.4

Second instance:

Jira: v8.20.13

ScriptRunner: 8.1.0

Checklist: 6.2.4

3 answers

4 votes
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.
September 22, 2023

Hi @Alfira Merinova

I have gone through your description, and I have to say, unfortunately, Okapya Checklist is not currently supported by ScriptRunner's Behaviour. Hence, you are getting the current result.

However, a new feature request for this has been created. For your reference, the change request key is SRJIRA-2768.   

This feature may be added in future releases.

Also, the current documentation on ScriptRunner provided by Okapya does not apply to ScriptRunner's Behaviour. It is meant for Listeners / Post-Functions / Scripted Fields. Let me know if you want to try something using one of these, and I will try to provide an example. 

Another alternative I can suggest is to use the Standard Checklist provided by Jira. I can provide some examples using the Behaviour with the Standard Checklist.

Thank you and Kind regards,

Ram

Alfira Merinova September 24, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thank you for the clarifications.

 

Another alternative I can suggest is to use the Standard Checklist provided by Jira. I can provide some examples using the Behaviour with the Standard Checklist.

Yes, please, that would be very helpful. Could you please share these examples? I can replace Okapya Checklist with Standard Checklist, and need to implement behavior for these requests:

  1. Set several Checklist options "checked" based on the other custom field value on Create/Edit Screen.
  2. Another request is to make all options in Checklist read-only except one particular option on Create/Edit screen.
Like Josh likes this
2 votes
Maxime Lefebvre _Okapya_
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.
September 22, 2023

Hi Alfira,

Like Ram said, ScriptRunner Behaviours don't currently work with Checklist for Jira.

We have been working in collaboration with Adaptavist to eventually make it work. I will link your community post within our system and we will contact you in this post if/when we release an update that supports Behaviours.

Have a nice day!
Maxime

Alfira Merinova September 24, 2023

Hi @Maxime Lefebvre _Okapya_ , Thank you for letting me know. Yes, please, keep me informed.

Pascal Perreault _Okapya_ June 18, 2024

Hi @Alfira Merinova,

We just released checklist 7.1.0 which includes the ability to use ScriptRunner Behaviors to manipulate checklists!

See our documentation for more details!

Kind regards,

0 votes
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 22, 2023

@Ram Kumar Aravindakshan _Adaptavist_  This is for you expert. :)

Wojciech Wardaszko _HeroCoders_
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.
September 22, 2023

Actually, I believe this is for @Maxime Lefebvre _Okapya_ or @Pascal Perreault _Okapya_ ;)

Suggest an answer

Log in or Sign up to answer