Adding checklist in workflow transition based on Labels

Heya,

 

This is specifically related to the Checklist for JIRA plugin. The documentation page in question.

I am trying to add a specific checklist based on labels. I've made the workflow so this specific checklist is added only when labels = Draft:

image2016-8-22 15:37:19.png

 

However, it seems to ignore it and it adds that checklist even when the label is something different:

image2016-8-22 15:39:18.png

 

I am spawning 5 tasks (same Issue Type) at the same time and I want to add a different checklist to each of them. It seems like the only way to do this is to use Labels so I modified my workflow to add this. However, it doesn't seem to be working as all 5 issues (different Labels) get the same checklist I specified for Draft only. Any ideas / help?

4 answers

1 accepted

Hi Ovidiu,

Sorry for the delay, I somehow missed the email telling me about the question sad

First thing that comes to my mind is, and sorry to ask, did you publish the workflow. It happened to me many times smile

Also, yes, I was planning to eventually add more flexibility to the conditional rules ... even allow adding customfield values.

Yes, the workflow is published.

 

Let me explain what I'm doing (even behind the curtains):

  1. I have an Epic that spawns 5 tasks (Draft, Pre-Alpha, Alpha, Pre-Beta, Beta) using scriptrunner Clone issue and Links.
    1. In this clone issue postfunction, I also set a custom field called Stage to Draft, Pre-Alpha etc.
  2. In the (above) task workflow, before the issue creation, I have a postfunction that copies Stage to Labels. This ensures that the Label is correct on creation and is not just edited in afterwards:
    image2016-8-26 11:11:14.png

 

As you can see below, this is actually the case.

image2016-8-26 11:16:6.png

 

I've tried a few things:

  • Setting the checklist before the issue is created (doesn't work, no checklist is added)
  • Adding another checklist postfunction (for Pre-Alpha label) ignored it and added only the Draft checklist. EVEN THOUGH the Pre-Alpha checklist was before the Draft checklist in the postfunction order
  • Copying the Stage value to the Labels field AFTER issue creation doesn't work as the Label isn't set at all so the Checklist isn't added to any issue

The are a lot of reasons why I'm setting a custom field (stage) instead of a label on task creation:

  • I don't like labels
  • It's very easy to set conditions and work with custom fields in post functions
  • I can easily copy from custom field to other fields
  • I don't like labels
  • It's easy for people to (accidentally remove or edit labels). The custom field is a hidden value that is used just for workflow purposes
  • Setting a label programmatically is more clunky than setting a custom field
  • I don't like labels

 

Actually to be honest I tried setting a label in the original workflow (when I set the Stage) but I couldn't manage it. Maybe that would fix it? Idk..

I used the code in this ticket and it failed the postfunction with no logs: https://answers.atlassian.com/questions/216834

Any idea? Sorry to press this but I'd like to give my team an idea if they can expect to have this or try to find a different solution smile

I should note that I just checked and manually creating the issues and manually adding the Labels on the create screen correctly triggers the post-functions.

It's just that when I create the issue through a Clone & Link issue it doesn't work anymore which really throws a wrench in my plans.

 

Is it possible to set the Checklist in the Additional Issue Actions when I create each of the 5 Issues? I'd only need to set this once so I wouldn't be against it if you can give me the code needed.

image2016-8-30 13:32:47.png

Hi Ovidiu,

I am getting really annoyed with Answers! It seems that I don't get notified of some of your postings. For example, when I never received any notification for your answer stating that you did publish the workflow and when I checked manually, your reply was not there.

Anyway, one of the thing that I wanted to ask was to go through the step manually. You did that and it worked. I remember someone trying to do something similar and the post-workflow triggers were never ran when transitioning the issue programmatically. It seems that you have the same issue.

I effectively think that you could create the checklist via Script Runner. I don't know of all the required code (never used script runner) but I can point you to how set the data in. This is a post on answers where I guided a developer on how to change the values of checklist. You can inspire yourself to do the same. Simply pre-create the Checklist field with no values in it. During the transition, add the items programmatically.

https://answers.atlassian.com/questions/39233766

Yves

 

I used the code in that ticket and it worked (to add 1 checklist item). I'm not that tech-inclined to figure out how to add multiple checklist items so I asked Joshi if it's possible to share his solution - hopefully he can answer smile

 

Thanks a lot for your time. And if possible to include another rule on adding checklists (such as custom field value) I think that would be a nice feature to have. For now I'll do it programmatically.


Ovidiu. 

Cannot vouch for the code but try something like:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf = customFieldManager.getCustomFieldObjectByName("Pre-Release Task");
def cfConfig = cf.getRelevantConfig(issue)
def cfType = cf.getCustomFieldType()
def values = []
values << cfType.getSingularObjectFromString('{"name" : "My Checklist Item 1", "checked" : true, "mandatory" : false}')
values << cfType.getSingularObjectFromString('{"name" : "My Checklist Item 2", "checked" : true, "mandatory" : false}')
values << cfType.getSingularObjectFromString('{"name" : "My Checklist Item 3", "checked" : true, "mandatory" : false}')
issue.setCustomFieldValue(cf, values)

That works 99.9%* perfectly, thanks a lot! I guess just one more question to wrap up this workaround: Can you please help me clear the checklist via scriptrunner as well? I assume it's pretty similar except at the end it's:

issue.setCustomFieldValue(cf, null)

Am I correct?

 

 

*I have no idea why but the order of the items is off. Even though I have them as 1, 2, 3.. the order in JIRA is 3, 1, 2 which makes no sense. In any case, this is a minor problem which, if consistent, I can work around.

image2016-8-30 15:54:9.png

Edit: if I open the checklist to edit it, they rearrange themselves correctly (3,2,1). Weird but not a big problem:

image2016-8-30 16:2:56.png

If

issue.setCustomFieldValue(cf, null)

doesn't work, simply try with an empty array

issue.setCustomFieldValue(cf, [])

 

As for the order, it probably takes the order in which they were inserted into the array (probably reverse order). So simply change that order to get what you want. If you always recreate the checklist from scratch, you can add the value "rank" to the item such as:

'{"name" : "My Checklist Item 1", "checked" : true, "mandatory" : false, "rank" : 0}'

Null worked, also being able to specify the rank is awesome. 

Thanks a lot Yves, I'll mark this as resolved.

Also just as a side-note, it would be really cool if we had more options to Conditional Rules. Labels and Issue Type are really not flexible enough smile

Anyone? Is this a known issue? Am I doing something wrong?

Any help appreciated. 

I'm not quite sure what you want to achieve.
If you are searching for a checklist based on labels you can try Label Manager for JIRA https://marketplace.atlassian.com/plugins/rs.codecentric.label-manager-project/server/overview 

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

72 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you