Hi Community, we recently started using "Checklist for Jira" from Okapya. I found a listener script from their documentation that can add a checklist template to an issue. I created a template and added the option "Account created", "Disk assigned" "Phone number assigned" "Laptop assigned" etc. I tested it's working fine. However, I would like to display the list of options based on component selection. For example, if a user selects the component "Onboarding" then should display a template else it should be an empty checklist where the user can create their own checklist option. How can add a condition to associate the template with a component?
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.component.ComponentAccessor;
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*;
import com.okapya.jira.customfields.configuration.*;
def issue = event.issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistField = customFieldManager.getCustomFieldObject("customfield_16200");
def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType();
def templateId = 1;
Template template = checklistCFType.templatesManager.getTemplate(templateId);
Collection<ChecklistItem> templateItems = ChecklistSerializer.deserializeChecklist(template.getItemsJson());
Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue);
items.addAll(templateItems);
checklistCFType.updateValue(checklistField, issue, items);
Thank you for your help!
Hi Shah,
I am a developer from Okapya and will help you with adding a condition for your component.
Take a look at this example:
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.component.ComponentAccessor;
@WithPlugin("com.okapya.jira.checklist")
import com.okapya.jira.customfields.*;
import com.okapya.jira.customfields.configuration.*;
def issue = event.issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def checklistField = customFieldManager.getCustomFieldObject("customfield_16200");
def checklistCFType = (ChecklistCFType) checklistField.getCustomFieldType();
Collection<ChecklistItem> items = (Collection<ChecklistItem>) checklistCFType.getValueFromIssue(checklistField, issue);
if ('MyComponent' in issue.components*.name) {
def templateId = 1;
Template template = checklistCFType.templatesManager.getTemplate(templateId);
Collection<ChecklistItem> templateItems = ChecklistSerializer.deserializeChecklist(template.getItemsJson());
items.addAll(templateItems);
}
checklistCFType.updateValue(checklistField, issue, items);
Make sure you change `MyComponent` to the component name you want.
Kind regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is great to hear!
If you wanted to use Automation for Jira, we do have an "Import Template" action that would do it. Just make sure you've got version 6.2.0 or later installed.
Have a nice day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Maxime Lefebvre _Okapya_ I forgot to ask. Is it possible to hide the checklist field for the rest of component just make it visible only for that component?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want the empty checklist to be hidden, you can disable the Show Checklist With No Items parameter. But this will only hide the checklist from the issue detail (once it's saved).
When the issue is opened in a dialog (Create or Edit dialog), the checklist will still be visible.
I think you can use ScriptRunner behaviors to also hide the Checklist field from the dialogs. Take a look at their explanation video.
I hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Shah Baloch
I am using a different checklist add-on so not 100% sure this will be useful to you, but here's how I'd approach this.
I'd try creating an automation rule. You can pick the "if/else block" for conditions and fill in Field with the "Components" value, select Condition and Value.
Select "Edit issue" for action and choose the "Checklists" field and fill in the value that needs to be added as a checklist to the created request based on the selected component. Do the same for the 'Else" block.
This example comes from a cloud Jira instance and you'll likely want to use Automation for Jira on a Server instance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Oleksandr Siryi_Railsware_we found Checklist for Jira better than others we tried. It didn't show in automation's action tab. Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, glad you found the solution)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.