Skip to main content
Skip table of contents

Remove Due Date when the item is checked

This example shows how you can modify the existing checklist value. You can use this example to implement your desired use case. In this case, we are removing the due date as soon as an item is checked.


Steps

  1. Create a new ScriptRunner Behaviour and select the desired project and issue type mappings.

  2. In the Add field section, add the Checklist field.

    image-20240517-132902.png

  3. Select Create script to add a script when your Checklist field changes.

    image-20240517-133059.png

  4. In the script, use the following snippets:

    • Retrieve the existing value of the checklist:

      GROOVY
      def checklistFieldName = "DoD";
      def checklist = getFieldByName(checklistFieldName);
      String value = checklist.getFormValue();
      Collection<ChecklistItem> items = ChecklistSerializer.deserializeChecklist(value);
    • Remove the due date of any item that is checked:

      GROOVY
      items.forEach { item ->
          if (item.isChecked()) {
              item.setDueDate(null);
          }
      }
    • Update the value in the checklist field.

      GROOVY
      String newValue = ChecklistSerializer.serializeChecklist(items);
      checklist.setFormValue(newValue);

Full Example

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

def checklistFieldName = "DoD";
def checklist = getFieldByName(checklistFieldName);
String value = checklist.getFormValue();
Collection<ChecklistItem> items = ChecklistSerializer.deserializeChecklist(value);

items.forEach { item ->
    if (item.isChecked()) {
        item.setDueDate(null);
    }
}

String newValue = ChecklistSerializer.serializeChecklist(items);
checklist.setFormValue(newValue);
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.