Just a bit of background on me: I've been programming/scripting for 20 years, starting with C+ (forgot all of it) and currently consider myself advanced with PowerShell. No Groovy/Java experince.
Background on task: We have a security form that has 4 potential assignee's. I has approvers so I need to break it down into sub-tasks with each subtask having an approver. Instead of someone creating a subtask for each person I decided to automate it.
My automation got out of hand. So I have a script that figures out who needs a subtask based on the form that was submitted, but if I do something like this in the future, I would like to figure out how to simplify it.
Could someone take a look?
{% if issue.fields.customfield_10121 | find({"value":"Windows"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Oracle"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Phone"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
NT Sub-task,Oracle Sub-Task,Phone Sub-task,Jira Sub-task
{% else %}
NT Sub-task,Oracle Sub-Task,Phone Sub-task
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
NT Sub-task,Oracle Sub-Task,Jira Sub-task
{% else %}
NT Sub-task,Oracle Sub-Task
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Phone"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
NT Sub-task,Phone Sub-task,Jira Sub-task
{% else %}
NT Sub-task,Phone Sub-task
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
NT Sub-Task,Jira Sub-task
{% else %}
NT Sub-task
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Oracle"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Phone"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
Oracle Sub-task,Phone Sub-task,Jira Sub-task
{% else %}
Oracle,Phone Sub-task
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
Oracle,Jira Sub-task
{% else %}
Oracle
{% endif %}
{% elif issue.fields.customfield_10121 | find({"value":"Phone"}) != null %}
{% if issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
Phone Sub-task,Jira Sub-task
{% else %}
Phone Sub-task
{% endif %}
{% else %}
Jira Sub-task
{% endif %}
Just so you know, my brains are mush after keeping everything in mind, but it works!
Source I used to start this: 3. Configuring Post Functions (innovalog.com)
Hi @Chris Thomas ,
did you look into using the "in" Nunjucks filter:
{% if issue.fields.customfield_10121 | field("value") | in("Windows","Oracle","Phone","Jira") %}
The "field" filter will return an array of the value of the "value" field for each selected option/checkbox, and the "in" filter will return true if at least one element of the array is in the list of values passed as parameters.
Thanks for the reply.
I thought about this off and on and I can't see how it can help in this situation. There is a custom form with 4 options and for every option a customer selects I need to return a specific response for the subtasks to be created. This code just tells me if a value is present, not direct to a proper response.
That said yesterday was the first time I did any Nunjucks and I can see some ways using "in" will be very helpful. For example in a project with lots of components. I really do appreciate the tip.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure I understood your requirements properly. Your code is quite complicated so I'm not sure I understand what it's doing, but maybe I can guess: for each checked option of a checkboxes field (customfield_10121), you need to return a value which will become the summary of a new sub-task. Is that correct?
In that case, you can do this:
{% set subtasks = [] %}
{% if issue.fields.customfield_10121 | find({"value":"Windows"}) != null %}
{% set ignored = subtasks.push("NT Sub-task") %}
{% endif %}
{% if issue.fields.customfield_10121 | find({"value":"Oracle"}) != null %}
{% set ignored = subtasks.push("Oracle Sub-task") %}
{% endif %}
{% if issue.fields.customfield_10121 | find({"value":"Phone"}) != null %}
{% set ignored = subtasks.push("Phone Sub-task") %}
{% endif %}
{% if issue.fields.customfield_10121 | find({"value":"Jira"}) != null %}
{% set ignored = subtasks.push("Jira Sub-task") %}
{% endif %}
{{ subtasks | join(",") }}
Is that what you were looking for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That seems exactly what I was looking for.
Thank you very much for your time, now off to do a few hours of learning how it works!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Once you confirm it works, can you "Accept" the answer so that the answer can be found by other Community members?
Thanks,
David
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.