Webservice Dynamic Multilabel looping with Jira Rest API
Asked by SPadalkar:

Hi,

I am trying to create multiple Jira tickets based on the multiple selections made my the user in the confiforms form. I am using Webservice Dynamic Multilabel to pull the dropdown options from an attached spreadsheet. (looking at a few posts, it might be better to pull from Jira createMeta API. But that I will try later)

I have velocity code in the Applink body to loop through the selection and generate payload dynamically for one ticket each. But foreach doesn't seem to work for me. It simply skips the whole body.

I also don't fully understand the difference between Webservice Dynamic Multilabel and Websrvice Multiselect. I got Webservice Dynamic Multilabel working so continued using it.

#foreach ($r in $Requestor) $r.fullName #end

```
<table>#foreach( $customer in $customerList )    <tr><td>$foreach.count</td><td>$customer.Name</td></tr>
--I tried building the Jira payload here--#end</table>?
```


Answers:
author: Alex Medved _ConfiForms_
body: Hi

You cannot have multiple (JSON) payloads in the IFTTT. Well you can construct whatever you want but processed body will be submitted just once. Using the configuration you have

Differences between Multi-label/Multi-select - in visual appearance mainly. Multi-select also allows you to show a label, but save the "id". Multi-label stores exactly what you see

Alex

comments: author: SPadalkar
body: Thanks for your quick response!

I am trying to generate a single payload with multiple Issue updates using Jira bulk API if possible. I want to create a new ticket for each value of FArea. I have used the "/rest/api/latest/issue/bulk" endpoint to create multiple Jira ticket in the past. But here I need to loop through the selected values.   

{  
"issueUpdates":\[  
#foreach ($r in $FArea)  
{  
"fields":{  
"project":{  
"key":"JSTEST"  
},  
"summary":"\[entry.Outcome\]",  
"description":"\*Support:\* \[entry.Outcome.escapeJavaScript\] #foreach ($r in $FArea) $r #end",  
**"customfield_30984":"$r",**   
"customfield_27817":{  
"value":"No"  
},  
"customfield_12780":"\[entry.JiraEpic.key\]",  
"issuetype":{  
"id":"9"  
}  
}  
}  
#if( $foreach.hasNext ) , #end  
#end  
\]  
}


author: Alex Medved _ConfiForms_
body: What do you have in "$FArea" variable?

Also, make sure that Velocity templating is NOT disabled in your instance by Confluence administrators

Also, ConfiForms uses/relies on the Velocity version used (and provided) by Atlassian - it is a 1.6.3.something (depends on your Confluence version)... so there is no $foreach.hasNext


author: SPadalkar
body: FArea is a Confiforms form field of type Websrvice Dynamic Multi label Dropdown. Velocity code works with simple variable setting etc. For example I set a link to epic in a variable and print it in the ticket successfully.

The test code *#foreach ($r in $FArea) - $r - #end*is currently printing the response below. I have selected 3 items in the dropdown.

org.dom4j.tree.DefaultElement@4c39c005 \[Element: \<value attributes: \[\]/\>\]

Also the following line of code works as expected. It sets up the values in the Jira dropdown correctly.

"customfield_30984":\[\[entry.**FArea**.asArrayOfKVPairs(value)\]\],


author: Alex Medved _ConfiForms_
body: Try the following

```
#foreach ($r in $FArea.getIds()) - $r - #end
```

There is also

```
getAsIdLabelPairs()
```

and

```
getLabels()
```

methods

Alex


author: SPadalkar
body: Thanks, Alex.

This worked (I think).

```
#foreach ($r in $FArea.getIds()) - $r - #end
```

It's now breaking at this line. #if( $foreach.hasNext ) , #end

Here is the error I get now

Error communicating with Jira, {"errorMessages":\["Unexpected character ('{' (code 123)): was expecting comma to separate ARRAY entries\\n at \[Source: org.apache.catalina.connector.CoyoteInputStream@685682f3; line: 34, column: 9\]"\]}

I am thinking of using count instead of hasnext.


author: Alex Medved _ConfiForms_
body: Earlier I have answered this....

ConfiForms uses/relies on the Velocity version used (and provided) by Atlassian - it is a 1.6.3.something (depends on your Confluence version)... so there is no $foreach.hasNext


author: SPadalkar
body: Yes, yes. I am thinking of using count to track the last item on the list instead of $foreach.hasNext.

Really appreciate your quick help here. Will report back on the success of the alternative. :)


author: SPadalkar
body: Thanks for your help with the above, Alex. The count worked.   

But I am having a similar issue with other dropdowns in the same form. I have a user picker field for subscribers. I would ideally like to add the listed users as watchers. But I am seeing issues with Jira watchers API online. So thought of tagging the users in the description field.

The following code prints the usernames in a list.

```

"description":"Subscribers: [entry.subscribers.asUsers.transform(username)]  \r\n*Outcome:* [entry.outcome.escapeJavaScript].", 
```

I need a way to convert the username into a tag within Jira description field.

I tried [this](https://wiki.vertuna.com/display/CONFIFORMS/How+to+reference+a+multi-select+user+values+in+IFTTT+macro+body) option

```
#foreach ($r in $subscribers) [~$r.username] #end
```

This prints "\[\~$r.username\]" does not print the value of $r.username.   

In other cases it prints the object and not values whenever I try to put the Jira formatting around the options.   

Seems like my version of velocity behaves a little differently that what Atlassian documents. Appreciate your help.


author: Alex Medved _ConfiForms_
body: Hi

what is "subscribers"? A user picker? Velocity variable does not contain a user object, so there is no "username" property

It should be a username itself

```
#foreach ($r in $subscribers) [~$r] #end
```

Alex


author: SPadalkar
body: Yes, subscribers is a user picker field.

The foreach loop above does not print anything. Here is what I see in the ticket.

```
Subscribers:

Outcome: Test. Please ignore.
```


author: Alex Medved _ConfiForms_
body: ```
#foreach ($r in $subscribers.getIds()) [~$r] #end
```

Try the above (as it is also a multi-value field)


author: SPadalkar
body: No difference. :(


author: Alex Medved _ConfiForms_
body: I dont know, quickly checking the above I can see it works

![Screenshot 2022-01-13 at 17.57.04.png](https://community.atlassian.com/t5/image/serverpage/image-id/177659i695F954D7692611F/image-size/large?v=v2&px=999 "Screenshot 2022-01-13 at 17.57.04.png")

"subscribers" is a "user (multiselect)" field

Alex


author: SPadalkar
body: Oops. My error in this last instance. I had a typo in the field name. Apologies.

The code below worked! Really appreciate your quick responses, Alex!

```
#foreach ($r in $subscribers.getIds()) [~$r] #end
```


Tags: confiforms

confluence-server

server