Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Webservice Dynamic Multilabel looping with Jira Rest API

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> 

 

1 answer

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

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
]
}

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

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)]],

Try the following

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

There is also

getAsIdLabelPairs()

 and

getLabels()

methods

Alex

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. 

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

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. :)

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 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. 

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

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.
#foreach ($r in $subscribers.getIds()) [~$r] #end

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

No difference. :( 

I dont know, quickly checking the above I can see it works

Screenshot 2022-01-13 at 17.57.04.png

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

Alex

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

🏠 Say hello to the new Confluence Home!

Hi Atlassian Community, My name is DJ Chung, and I’m a Product Manager on the Confluence Cloud team. Today, I’m excited to share a new and improved version of Home. The new Home helps you ...

38,679 views 28 126
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you