Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using IFTTT and Velocity to Create bulk JIRA issues by iterating over a comma separated list

John Hamilton October 26, 2023

I'm using Confiforms to try and build a WebService Request to try and create a set of tasks based on the number of items that the user supplies into a Text field.  The Text field format should be a comma separated list, and is stored in "TestScriptsToRun".

I have all the linkages working, and am able to submit single creates, but I can't get the bulk to work...

Here's my code. 

{
    "issueUpdates":[
	
	#set($TSToRun = "[entry.TestScriptsToRun.split(,).toArray(')]")
	#foreach ($script in $TSToRun)
    {
	  "fields": {
         "project":
         {
            "key": "PRJT"
         },
         "summary": "Run $script for [entry.SourceStory.key]",
	     "components": [{"name": "Software"}],
         "description": "\n\n**Automatically Generated from Confluence**\n\n",
	     "labels": [ "AutomatedTask" ],
         "issuetype": {
            "name": "Story"
         }
      }
	  #if($script != $TSToRun.get())
	},
	  #end
	#end

	}

  ]
}

Here is the error I receive.

  • Requested to https://<serveraddress>/rest/api/2/issue/bulk has resulted in an error. Response code = 400 (method ='POST'). Response contents: {"errorMessages":["Unexpected close marker '}': expected ']' (for ARRAY starting at [Source: org.apache.catalina.connector.CoyoteInputStream@13dc366; line: 2, column: 4])\n at [Source: org.apache.catalina.connector.CoyoteInputStream@13dc366; line: 5, column: 3]"]}

Thanks for your help!

1 answer

1 accepted

0 votes
Answer accepted
Alex Medved _ConfiForms_
Community Champion
October 27, 2023

Hi @John Hamilton and welcome to this community

In ConfiForms the template are processed as follows:

  1. Evaluated as Velocity template 
  2. Processed for [entry.field_name] notations and expressions

In other words the

#set($TSToRun = "[entry.TestScriptsToRun.split(,).toArray(')]")

Does not get the value from TestScriptsToRun field when this is processed as a Velocity template

Alex

John Hamilton October 27, 2023

@nurac: Thanks!  Any ideas on how to get this where I want it? If [entry.TestScriptsToRun] looks like:

TEST_123_01, TEST_123_02, TEST123_03

is there a way to get the velocity template to work?

Alex Medved _ConfiForms_
Community Champion
October 27, 2023

Something like this

#foreach ($script in ${TestScriptsToRun.split(",")})
  ${script} <br/>
#end 

(of course not the <br/> in there... I just did a test with a PlainView for a quicker debugging method)

Screenshot 2023-10-28 at 09.28.46.png

Alex 

John Hamilton October 30, 2023

Thanks Alex!  I got the above working in PlainView, now I'm working on the second condition (the if statement) that will allow me to push add in the correct closing bracket for the JSON, but only for the last item in the split.

Here's what I've got.  I can't get the equality to fire...

#foreach ($script in ${TestScriptsToRun.split(",")})
   ${velocityCount} ${script}<br/>
   [entry.TestScriptsToRun.split(",").get()] <br/>
   #if(${script} == ${TestScriptsToRun.split(",").get()})
      "Addition at the end" <br/>
   #end
#end

Appreciate your help! 

Alex Medved _ConfiForms_
Community Champion
October 30, 2023

I dont think there is a velocityCount - as Confluence uses a pretty old version of Velocity templates https://velocity.apache.org/engine/1.7/user-guide.html

The best option is to iterate through and get the last one set to some extra variable you define on top of the foreach loop

John Hamilton October 30, 2023

Awesome!  Took a while, but I finally got it working, and it seems to create the right JSON.  Unfortunately, now I'm getting a different error.

Requested to https://<server>/rest/api/2/issue/bulk has resulted in an error. Response code = 400 (method ='POST'). Response contents: {"errorMessages":["Unexpected character ('Â' (code 194)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@26a77e56; line: 3, column: 3]"]}

Not sure what to do here.  To troubleshoot, I copied the script from the "No Format" box to the "PlainView" box with no changes.  The JSON that is produced works in a JSON parser and validator against the JIRA API.

I have success when I create a single issue without any of the Velocity scripting (through the create single issue call), but I can't get it to work through this call.

Here's my current code:

 

#set ($myLast = "")
#foreach ($script in ${TestScriptsToRun.split(",")})
 #set ($myLast = $script)
#end
{
    "issueUpdates":[
 #foreach ($script in ${TestScriptsToRun.split(",")})
    {
   "fields": {
         "project":
         {
            "key": "PRJT"
         },
         "summary": "Run $script for [entry.SourceStory.key.escapeJSON]",
      "components": [{"name": "Software"}],
         "description": "\n\n**Automatically Generated from Confluence**\n\n",
      "labels": [ "AutomatedTask" ],
         "issuetype": {
            "name": "Story"
         }
      }
   #if(${script} != ${myLast})
 },
   #end
 #end
 }
  ]
}

Any idea what I've missed?

Alex Medved _ConfiForms_
Community Champion
October 30, 2023

Could be a last "," ?

Jira is known to be very tentative about the JSON posted... and vague about the error messages

Alex

John Hamilton October 30, 2023

The error states it's getting some form of 

'Â' (code 194)

in the file.  I have no idea how it would get that. 

I put the JIRA API JSON Schema and my resulting JSON into a parser, and it all looks just fine... I don't see any extra commas anywhere.

Here's the raw output from the "Plainview" box.

{ "issueUpdates":[     { "fields": { "project": { "key": "PLGN" }, "summary": "Run PLGN_999_99 for PLGN-3002", "components": [{"name": "Software"}], "description": "\n\n**Automatically Generated from Confluence**\n\n", "labels": [ "AutomatedTask" ],       "issuetype": { "name": "Story" } } },     { "fields": { "project": { "key": "PLGN" }, "summary": "Run PLGN_999_98 for PLGN-3002", "components": [{"name": "Software"}], "description": "\n\n**Automatically Generated from Confluence**\n\n", "labels": [ "AutomatedTask" ],       "issuetype": { "name": "Story" } } } ] }

And here's what it looks like when prettied up a little.

{
"issueUpdates": [
{
"fields": {
"project": {
"key": "PLGN"
},
"summary": "Run PLGN_999_99 for PLGN-3002",
"components": [
{
"name": "Software"
}
],
"description": "\n\n**Automatically Generated from Confluence**\n\n",
"labels": [
"AutomatedTask"
],
"issuetype": {
"name": "Story"
}
}
},
{
"fields": {
"project": {
"key": "PLGN"
},
"summary": "Run PLGN_999_98 for PLGN-3002",
"components": [
{
"name": "Software"
}
],
"description": "\n\n**Automatically Generated from Confluence**\n\n",
"labels": [
"AutomatedTask"
],
"issuetype": {
"name": "Story"
}
}
}
]
}
Alex Medved _ConfiForms_
Community Champion
October 30, 2023

Could you post the same json directly using the Jira REST API?

John Hamilton October 30, 2023

Do you have a recommended way of doing that?

Alex Medved _ConfiForms_
Community Champion
October 30, 2023

For example as shown in the official examples by Atlassian https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

John Hamilton October 30, 2023

After a little trial and error, I was able to get it to post successfully using the command line.  I have created stories in JIRA from the raw JSON.  I got it to work with both the single line, and with the "pretty" formatted line.  Everything looks right on the individual issues.

Unfortunately, still no luck using the Confiforms Webservice Call...

Is there any way to pickup the exact JSON that's being sent by Confiforms?

Any other ideas?

Alex Medved _ConfiForms_
Community Champion
October 31, 2023

The best way is to check with Confluence logs - that should be logged there

Alex

John Hamilton October 31, 2023

Unfortunately, we can't find it in the Confluence logs.  We've got Debug turned on for the form, and there was additional debugging info, but couldn't find the JSON that was sent.  Any other ideas?

Alex Medved _ConfiForms_
Community Champion
November 1, 2023

Hi

If you have enabled DEBUG level logs for ConfiForms as per https://wiki.vertuna.com/display/CONFIFORMS/How+to+enable+debug+logging+for+ConfiForms+app then the logging is very verbose - it logs the JSON it is about to post and logs a lot of details if the request has failed

 

You should see something like from a ConfiForms logger

"Could not complete request, <SOME_MESSAGE_HERE> Used input: '<YOUR_JSON>'"

 

Alex

John Hamilton November 1, 2023

First problem solved, it was barfing on tab characters in the input.  So, if anybody else gets Code 194 errors, it's likely due to somebody (in this case me) using tab characters instead of spaces.  Really, I should know better by now!

Onto the second problem: It appears as though we aren't authenticating with the JIRA instance through the webservice call.  The admins don't believe this is doable in our security context, so I'm stuck again, and may be forced to using the "Create JIRA Issue" call (which I know works, but only creates a single issue).

Any ideas on how to take a single form submission and create multiple form entries (to trigger multiple "Create JIRA Issue" IFTTT calls?

If not, I may have to resort to "Here's your Excel Template.  Fill it out, and upload..."

Alex Medved _ConfiForms_
Community Champion
November 1, 2023
John Hamilton November 1, 2023

That did it! Works awesome!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events