Get the HTML content of a specific issue using ScriptRunner

Hi

I would like to get the Attachment HTML section of a specific issue in script

is there a way to retrieve the issue HTML using scriptrunner?

thanks

Dar

1 answer

0 votes

I'm not sure what you mean by "the attachment html section", but I will guess that what you mean is "the displayed panel headed attachments when I look at an issue"

That is generated when you view the issue, not stored, so there's nothing to "get".  If your script needs to use the raw html of that panel, it's going to have to replicate the logic that generates it all.

Hi Nic,

I would like to display the parent attachment section on the sub task issue as a script field that take the parent HTML and returns the attachment element

thanks

Dar

 

Ok, a scripted field supports html output, so you can embed a lot of the table html you need in there.  Then your script will need to grab the parent issue from the current one, and iterate through the attachments on it to get the details from them.

You'll also want to write a listener that can catch attachment updates from the parent issues and trigger a re-index on the sub-tasks.

Hi Nic

maybe I didn't explained it right 

I would like to do something like this:

We have 2 issues 139 (parent) and 140 (sub)

and I would like to show the parents attachment under the sub issue using script field

is it possible?

thanks!

I Capture-attachment field.PNG

Er, that's what I specified.

 

Hi Nic

I actually tried to write a script that get the HTML of the issue but the script seems to get into infinite loop or something and don't return anything

if I change the URL to some general url (www.google.com for example) i can get the HTML

why is that?

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
String url = "http://localhost:8080/browse/TEST-11/";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
String userCredentials =  "user:pass" ;
String basicAuth = "Basic " + new Base64().encode(userCredentials.getBytes());
con.setRequestProperty("Authorization", basicAuth);
int responseCode = con.getResponseCode();
		
BufferedReader input = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = input.readLine()) != null ) {
	response.append(inputLine);             
}
input.close();
return response.toString()

thanks

You need to stop thinking in terms of "getting the html" and build it for yourself.  If you try to fetch from the same place, you've put yourself into an infinite loop.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

22,334 views 2 7
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you