How can I copy Multi-Level Cascading Select field from trigger issue instead of set values?
Asked by Kevin K:

Hi,

I am struggling with copying Multi-Level Cascading Select fields to subtasks through automation. The documentation and questions I found online point to fields with parent + child options. However, the fields I am working with have 3 or 4 options (great-grandparent+ grandparent + parent + child). How could I modify the JSON below to copy customfield_12800 and customfield_13815 from the trigger issue?

++This is the JSON I have input in the advanced section of automation. I would like to change 12800 and 13815 to copy values from trigger issue:++

{  
"fields": {  
"customfield_12800": \[{  
"value": "Bb"  
}, {  
"value": "All"  
}, {  
"value": "All"  
}\],  
"customfield_14703": {  
"value": "{{triggerIssue.fields.customfield_14703}}"  
},  
"customfield_13815": \[{  
"value": "Web"  
}, {  
"value": "Site"  
}, {  
"value": "Publish"  
}, {  
"value": "Standard"  
}\]  
}  
}


Answers:
author: Simmo
body: Hi [@Kevin K](/t5/user/viewprofilepage/user-id/4538600)

Could you provide an example of what the data from the trigger issue looks like and we might be able to figure out a smart value.

Cheers,

Simeon.

comments: author: Kevin K
body: Got it. So, these fields are copied from an original parent ticket to the trigger issue during automation. But are not carried down to tickets created by automation, so these 3 custom fields will need to be copied through this advanced section. I'd like to grab the values for 'Location'(customfield_12800) and 'Change Category'(customfield_13815) like I have with 'Location Region'(customfield_14703).

Here are snips of the custom fields on the ticket.![chg cat.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/176074i7F60377CF981AFE2/image-size/large?v=v2&px=999 "chg cat.PNG")![loc.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/176075iBB2A3B0C2279058F/image-size/large?v=v2&px=999 "loc.PNG")


author: Simmo
body: Hey [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

So I'm not sure how you managed to get the multi select cascading select. I couldn't get one setup. But no matter, I'll show you how we get to the answer instead.

First of all, we need to see the rest representation of these fields so I can figure out how we get the values you want. For the above issues that you provided screenshots, can you access them via this URL format:

```
https://YOUR_JIRA_INSTANCE/rest/api/2/issue/ISSUE_KEY?expand=names?
```

And then show me the second for both of the fields that you want to copy from the trigger issue? They'll look vaguely like:

```
customfield_10128: {
 self: "https://XXX/rest/api/2/customFieldOption/10437",
 value: "Top Fred",
 id: "10437",
 child: {
   self: "https://XXX/rest/api/2/customFieldOption/10439",
   value: "Second Fred",
   id: "10439"
 }
}
```

You might want to filter your instance name out of the URLs too.

This field here that i'm showing you is a two level multi select. If i wanted to access the child value I'd use the follow smart value:

```
{{issue.customfield_10128.child.value}}
```

Hopefully that starts to make some sense, if you can get the above information we should be able to dig into what your smart value would be.

Cheers,

Simeon.


author: Kevin K
body: Hi [@Simmo](/t5/user/viewprofilepage/user-id/3608665) ,

It looks like we use a plugin for the Multi-level cascading select custom fields. However, I've never used it to create. Hopefully this is what you are needing for the smart values of the fields:

"customfield_13815":\[{"self":"https://x/rest/api/2/customFieldOption/15207","value":"Web","id":"15207","disabled":false},  
{"self":"https://x/rest/api/2/customFieldOption/15717","value":"Sitecore","id":"15717","disabled":false},  
{"self":"https://x/rest/api/2/customFieldOption/27120","value":"Publish Content - Broadband","id":"27120","disabled":false},  
{"self":"https://x/rest/api/2/customFieldOption/27121","value":"Standard","id":"27121","disabled":false}\]

"customfield_12800":\[{"self":"https://x/rest/api/2/customFieldOption/12901","value":"Broadband","id":"12901","disabled":false},  
{"self":"https://x/rest/api/2/customFieldOption/13342","value":"AAFES","id":"13342","disabled":false},  
{"self":"https://x/rest/api/2/customFieldOption/22021","value":"All","id":"22021","disabled":false}\]


author: Simmo
body: Hey [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

So, your customfield_13815 field looks like:

```
[
  {
    "self": "https://x/rest/api/2/customFieldOption/15207",
    "value": "Web",
    "id": "15207",
    "disabled": false
  },
  {
    "self": "https://x/rest/api/2/customFieldOption/15717",
    "value": "Sitecore",
    "id": "15717",
    "disabled": false
  },
  {
    "self": "https://x/rest/api/2/customFieldOption/27120",
    "value": "Publish Content - Broadband",
    "id": "27120",
    "disabled": false
  },
  {
    "self": "https://x/rest/api/2/customFieldOption/27121",
    "value": "Standard",
    "id": "27121",
    "disabled": false
  }
]
```

Which means that the values are just a flat array, so the operations that apply to them can be found at <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/>.

Now are you wanting to copy the entire list from one field to another field of the same type?

If so, I think you can just do this:

```
{
  "fields": {
    "customfield_12800": {{triggerIssue.customfield_12800}}
  }
}
```

Otherwise, now that I understand the format of your field, let me know if you're trying to copy bits of it or what you're trying for.

Cheers,

Simeon.


author: Kevin K
body: Hi [@Simmo](/t5/user/viewprofilepage/user-id/3608665) ,

I am wanting to copy the entire list from one field to the same type field in a new ticket. However, I can't get it to work on those 2 fields. Only if I hard code values in there.

I also tried the format used for customfield_14703, but no luck. So from below, 14703 will successfully copy, but 12800 will not since it has 3 values.

{  
"fields": {  
"customfield_12800": {  
"value": "{{triggerIssue.fields.customfield_12800}}"  
},  
"customfield_14703": {  
"value": "{{triggerIssue.fields.customfield_14703}}"  
},  
"customfield_13815": \[{  
"value": "Web"  
}, {  
"value": "Sitecore"  
}, {  
"value": "Publish Content - Broadband"  
}, {  
"value": "Standard"  
}\]  
}  
}

#### [Create issue](https://jira.boingoqa.com/secure/AutomationProjectAdminAction!default.jspa?projectKey=CHG#/rule/22/841) {#toc-hId--486306133}

Error creating issue  
Location is required. (customfield_12800)


author: Bill Sheboy
body: Hi [@Kevin K](/t5/user/viewprofilepage/user-id/4538600)

Perhaps you could try using an iterator for that customfield_12800, treating it as a list, as described [here for multiselect fields](https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Multi-select-custom-field):

```
"customfield_12800" : [ {{#triggerIssue.fields.customfield_12800}} { "value": "{{value}}" } {{^last}}, {{/}}{{/}} ]
```

Kind regards,  
Bill


author: Simmo
body: Hi [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

did you try copying it in this format:

```
    "customfield_12800": {{triggerIssue.customfield_12800}}
```

```
?
```


author: Kevin K
body: [@Simmo](/t5/user/viewprofilepage/user-id/3608665) [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) Hi Guys,

I'm not sure how to convert these to JSON format, but here's what I tried with Simmo's option. Still doesn't want to copy that field.

{  
"fields": {  
"customfield_12800": {  
"value": "{{triggerIssue.customfield_12800}}",  
"customfield_14703": {  
"value": "{{triggerIssue.fields.customfield_14703}}"  
},  
"customfield_13815": \[{  
"value": "Web"  
}, {  
"value": "Sitecore"  
}, {  
"value": "Publish Content - Broadband"  
}, {  
"value": "Standard"  
}\]  
}  
}  
}


author: Simmo
body: Hi [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

I've taken your above example and formatted it to what I am trying to suggest:

```
{
  "fields": {
    "customfield_12800": {{triggerIssue.customfield_12800}},
    "customfield_14703": {{triggerIssue.fields.customfield_14703}},
    "customfield_13815": [
      {
        "value": "Web"
      },
      {
        "value": "Sitecore"
      },
      {
        "value": "Publish Content - Broadband"
      },
      {
        "value": "Standard"
      }
    ]
  }
}?
```

Note that because we're using smart values here the above now won't pass a JSON validator but it is what you want. The reason for that is that the smart value:

```
{{triggerIssue.customfield_12800}}
```

should output the reason of the JSON of the field and hopefully get us into a good place. Please give that a go and let us know how it turns out.

Cheers,

Simeon.


author: Kevin K
body: [@Simmo](/t5/user/viewprofilepage/user-id/3608665) Tried the above format, but Automation doesn't want it to pass. I tried it on this first create issue from the logs:

![chg logs.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/176537iB487B67378A12456/image-size/large?v=v2&px=999 "chg logs.PNG")


author: Simmo
body: Hey [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

No worries, so then where ever you have that create action, add a log action after it. Copy and paste the exact same JSON into the log action and then we can see what it is outputting. If you can paste that into a message inside a code block we might be able to figure out what it is doing.

Cheers,

Simeon.


author: Kevin K
body: [@Simmo](/t5/user/viewprofilepage/user-id/3608665) It looks like it's grabbing the correct values, but failing on the parse? Is this what you are looking for? I filtered out the instance name.

{ "fields": { "customfield_12800": {self=https:/x.com/rest/api/2/customFieldOption/12901, value=Broadband, id=12901, disabled=false}, {self=https://x/rest/api/2/customFieldOption/13342, value=AAFES, id=13342, disabled=false}, {self=https://x/rest/api/2/customFieldOption/22021, value=All, id=22021, disabled=false}, "customfield_14703": Central, "customfield_13815": \[ { "value": "Web" }, { "value": "Sitecore" }, { "value": "Publish Content - Broadband" }, { "value": "Standard" } \] } }


author: Simmo
body: Hey [@Kevin K](/t5/user/viewprofilepage/user-id/4538600),

Damn, it looks like it might be doing something weird with that custom field. Any chance that you can raise a support ticket for this? It would make it a lot easier.

Cheers,

Simeon.


author: Kevin K
body: Yeah, no worries. It might be because of the plugin as well. I appreciate the help in trying to debug this!


Tags: atl-gruland

cloud