Get the HTML content of a specific issue using ScriptRunner

Dar Kronenblum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2016

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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2016

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.

Dar Kronenblum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2016

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

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2016

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.

Dar Kronenblum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 28, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2016

Er, that's what I specified.

 

Dar Kronenblum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 29, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 29, 2016

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