Hello,
I need to print the html data of the issue description..
When I printed the description (issue.getDescription()) , I got this:
h5. *+General OS / DB / Browser / Machine Information:+* h3. bla bla bla *+Scenario Description and steps to recreate the problem:+* h3. bla bla *+Actual & Expected Results+* h3. bla *+Log file information:+* h3. Daniel Test *+Additional info:+* h3.
How can I print this as html.?
Thanks,
Daniel
Hi,
Using the REST API you can do it.
so you need to get your issue data via REST API, like this:
/rest/api/latest/issue/{issuekey}?expand=renderedFields
The important part is the "?expand=renderedFields"
In the JSON response that you will get, you will have "renderedFields" entity, all rich text (wiki render) fields will be there rendered to HTML.
So just call the REST API from your ScriptRunner groovy script as I mentioned
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I will guide how to use REST API.
Do you have Jira server or Cloud?
here you want to run the script? as a post-function in your workflow?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So in your script listener,
Write this:
//get the base url of Jira
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
//rest api request
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(baseUrl + "/rest/api/latest/issue/" + issue.getId() + "?expand=renderedFields");
Credentials credentials = new UsernamePasswordCredentials("username","passwrod");
client.getParams().setAuthenticationPreemptive(true);
client.getState().setCredentials(AuthScope.ANY, credentials);
client.executeMethod(method);
def response = method.getResponseBodyAsString()
method.releaseConnection();
"response" now hold the JSON data you got from the REST API.
Go through the JSON and find "description" field inside "renderedFields".
The value there is by HTML
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.*;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got error with those logs:
2018-10-16 07:01:43,102 WARN [common.UserScriptEndpoint]: Script console script failed: java.net.UnknownHostException: jira.wla.bmc.com at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:117) at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:157) at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at org.apache.commons.httpclient.HttpClient$executeMethod$1.call(Unknown Source) at Script2797.run(Script2797.groovy:43)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure of the error...
Maybe it's related to security/policy or some other company restrictions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't think the "baseurl" is the issue...
It makes more sense that the issue the REST API method, is there any chance you are blocked from performing REST API calls on your server?
Something your IT/System/Security department did to your servers?
I'm adding one of my champion colleges, maybe he will know...
@Alexey Matveev Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nir Haimov ,
We had problems with SLL . Now I succeed to get the JSON and found there the html data. How can I take it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Daniel,
I'm Happy the problem solved.
As i assumed it was SSL problem from your side and not something related to the code.
Any way, from Jira side i gave you the solution.
Sorry but i can't teach you how to code...
As this is general question of how to read and use JSON.
I suggest you will use some google for this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nir Haimov , I don't know how to work with JSON.. I only need to get the HTML description.. that was my question from the beginning..
I will be happy if you can write me the line.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add the following to import:
import groovy.json.*
Add this line after all the code i sent you:
def parsed = new JsonSlurper().parseText(response)
parsed.renderedFields.description
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nir Haimov,
I also have some problems calling the REST API and I am not sure if I should create a new question or if it is ok to ask in this thread :D
Anyhow, I created a REST endpoint with scriptrunner that calls the REST API because I need the renderedFields.
My problem are now the credentials. Is it possible to get the credentials of the logged in user or do I have to put username and password in the script. The script will be called by multiple users later so I was wondering if this is somehow possible. Thank you.
Best regards,
Basit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have posted a new question and tagged you there. Thanks! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.