Importing a template using ScriptRunner

You can reuse existing lists of items for different issues by importing a template into a checklist with ScriptRunner. A template’s owner and/or project administrator(s) can edit a template without editing the associated script.


Steps

  1. Find your template ID in the template list in Manage Apps.

  2. Get the custom field and custom field type of your Checklist field.

    def customFieldManager = ComponentAccessor.getCustomFieldManager(); // Replace the custom field ID with your custom field's ID def checklistField = customFieldManager.getCustomFieldObject("customfield_10101"); def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType();

     

  3. Get the template’s items with the ID from the first step.

    // Replace this ID with the template ID you want to use def templateId = 123 Template template = checklistCFType.templatesManager.getTemplate(templateId); Collection<ChecklistItem> templateItems = ChecklistSerializer.deserializeChecklist(template.getItemsJson());

     

  4. Add the template’s items to the existing items in the issue.

    Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue); items.addAll(templateItems);

     

  5. Update the issue with its new items.

Full example

Here is a full example where a template is appended to an existing checklist.


SERVER documentation (On Cloud? Go here.)
Have questions? Contact our Service Desk for help anytime.