Loop checkbox values or multiple select to create multiple projects

Originally asked by Iona Augustine on 02 July 2021 (original question)


Is there any way I can loop the value I get from the checkbox/multiple select and use it to determine which project in JIRA for a new issue to be created?

For example something along the way as below:

def checkboxCollection = replica.customFields."Create in the customer facing projects"?.
                                value?.
                                collect{
                                        a->
                                        nodeHelper.getOption (issue, "Create in the customer facing projects", a.value)
                                        }
For each (checkboxCollection) {
        issue.projectKey = nodeHelper.getProject(replica.project?.key)?.key ?: checkboxCollection
        issue.typeName   = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Service Request"
}

Answer by Andrii Markov on 28 July 2021

Hi Iona Augustine ,

I am sorry if I get you confused with my answer.

We would like to understand closely your requirements about this configuration.

For example:

There are two instances “A” and “B”.

“A” side has a multi-box selection custom field and there are values like: (“V1”, “V2”, “V3”) and they could be selected either in one or a few options, or even 0.

So, we would like to figure out how the B side should understand which project to choose by selected values on the A side? Could you please elaborate about it?

Thank you,

Andrii


Comments:

Iona Augustine commented on 02 August 2021

Hi Andrii,

In pseudo code, I probably put it as below

def remoteCheckboxes = replica."Remote Checkbox".collect {it.value}  
  

For each remoteCheckbox in remoteCheckboxes

{
    issue.projectKey = remoteCheckbox[X]  
}​

So if the value of remoteCheckboxes from “Remote Checkbox” is (“V1”, “V2”, “V3”), then 3 issues would be created in 3 different projects which are in V1, V2 and V3

I hope this helps.

Thanks!

Andrii Markov commented on 04 August 2021

Hi Iona Augustine ,

Thank you for the update!

I am working on the workaround for you

Kind Regards,
Andrii

Answer by Andrii Markov on 26 July 2021

Hi Iona Augustine ,

I am sorry for such a huge delay.

As a workaround I would like to suggest to make an array of your checkbox.
For example:

issue."Multi checkbox" = ["option 1", "option 2"]
issue."Multi checkbox" = replica."Remote Checkbox".collect {it.value}

Also, more information you could find over here:

https://docs.idalko.com/exalate/display/ED/How+to+synchronize+list+custom+fields

Kind Regards,
Andrii


Comments:

Iona Augustine commented on 27 July 2021

Hi Andrii,

How do I make of this? I am not looking to sync the field. I am looking to use the values in the field so I can loop it to determine which project in JIRA to sync my issue to.

I am more than happy to explain more if need better explanation.

Iona Augustine commented on 27 July 2021

I actually found this

def projectMapping = ["SERVA":"CLOUDA", "SERVB":"CLOUDB"] // ["REMOTE PROJECT KEY": "LOCAL PROJECT KEY"]
issue.projectKey = projectMapping[replica.project.key]

from this page:

https://docs.idalko.com/exalate/pages/viewpage.action?pageId=19629012

I modified it and used it as below:

def projectMapping = replica."Create in the customer facing projects".collect {it.value}

issue.projectKey = projectMapping[replica.project.key]
issue.typeName   = "Service Request"

The run the connection, I got the below error:

HTTP Status 400 – Bad Request

services.jcloud.exception.JiraCloudTrackerException: Could not find project `[]` in this Jira Cloud:

Answer by Iona Augustine on 06 July 2021

Hi Andrii, to top up my previous comment, the reson we use checbox is to be able to select multiply. The script you gave me is good is the selection is single.

We want to be able to select more than one selection and be able to loop it and create project based on it,

I hope this helps. Thanks!


Comments:

Serhiy Onyshchenko commented on 06 August 2021

Hello, Iona Augustine
As far as I understand your use case, you have a checkbox custom field on source side (let’s call it Source for now), the checkbox lists different project keys from Destination side.
A user on Source side is supposed to tick one or multiple boxes in this custom field, and you’d like that Exalate creates an issue on Destination side in each project, right?
Regards, Serhiy.

Iona Augustine commented on 09 August 2021

Hi Serhiy,

Yes! exactly that. So the script will be dynamic with less or no maintenance at all.

Thanks!

Iona

Answer by Iona Augustine on 05 July 2021

Thanks for that Andrii,

This should work, but I am looking something more dynamic, without specifying the value at all.

So if today I have 2 values within the checkbox i.e. Project A, project B, project C. Then tomorrow I added project D, I dont have to modify the script each time.

Does this make sense?


Answer by Andrii Markov on 02 July 2021

Hi Iona Augustine ,

You can try to create a condition with a revising if your checkbox has been checked or not.

Please notice that if you are sure that in your customfields all the checkboxes have some value, you should use a non-commented condition. If not, you should use the commented one.

Also, please let us know if it worked for you.

if (replica."Create in the customer facing projects".any {box->box.value == "example"})
//if (replica."Create in the customer facing projects"?.any {box->box.value == "example"})
        {
issue.projectKey = "example"
}​  
  
  
  


Comments:

Iona Augustine commented on 14 July 2021

Hi Andrii, anything on this yet? If it’s not possible then it’s OK, we’ll work a workaround.