Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×I'm creating a ScriptRunner Groovy event script in Confluence and I'm having problems with the "response" class object below. ScriptRunner shows an error with "[Static type checking] - No such property: data for class: java.land.Object"
import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page
def event = event as PageEvent
Page page = event.getPage()
Space space = page.getSpace()
if (space.key != 'eWebProjects') {
return
}
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*
def confluence = new RESTClient( 'https://confluence/rest/api/' )
def response = confluence.get( path: 'content' + page.id + '/page-type',
contentType: JSON)
def pageType = response.data
I've abandoned using ScriptRunner or any other tool that uses Groovy/Java Script and have resorted to using pure REST API and C#. This ensures that all interactions with JIRA/Confluence use Atlassian REST methods. We are getting away from using any third party add-ons within JIRA because we have found they add an addional layer of risk.
It would be great If Atlassian would make their own code editor with debuggin capabilities.
HI @Eric Dierkens I have a similar requirement in Jira my requirement is
Now I need make a REST call based on the Value selected in the Custom Field Can we do that
Example:
1) I have a custom Fields called
a) Location : aws, cnet, azure ---> Select List field
b) Instance Type: t2.nano, t2.micro, t2.small, t2.medium ----> Select List field
c) Owner ---> Text Field
d) Tag ----> Text field
e) Cost Center ---> Text field
f) Size of Memory ----> Text Field
g) Size of Disk -----> Text Field
2) Now When the issue got created in the Project based the Value in the cutom Field need make a REST call based on that
like : Now i'm creating a issue with Location= aws, Instance = t2.nano, Owner = xyz, Tag= my tag, Costcenter = 8500
Now When the Issue got Approved it has to Make a Rest Call and create a AWS instance in AWS based the Value i gave in the Custom Field
same like that if i create a ticket with different value Location= cNet, Size of Memory = 30, Size of Disk = 2024, Owner = xyz, Tag= my tag, Costcenter = 8500
Now it has to create a the Cnet instance based the Value i given the field when the ticket got approved
Can you please suggest me how to do it with script runner or any other way to do it
Thanks,
Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is how I fixed it.
import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page
def event = event as PageEvent
Page page = event.getPage()
Space space = page.getSpace()
if (space.key != 'eWebProjects') {
// log.warn("eWebRequest Form Save Event - this is not the eWebProjects space")
return
}
//Start processing here
import java.net.HttpURLConnection;
import groovy.json.StreamingJsonBuilder;
//import java.util.logging.Logger;
String pageJson = this.getJSON("http://confluence/rest/api/content/" + page.id + "/property/page-type/", 60);
if (pageJson == null)
{
return
}
import groovy.json.JsonSlurper
import com.fasterxml.jackson.databind.ObjectMapper
//log.warn("pageJson = " + pageJson)
ObjectMapper mapper = new ObjectMapper();
Object jsonSlurper = new groovy.json.JsonSlurper().parseText(pageJson)
Map jsonResult = (Map) jsonSlurper;
def pageType = jsonResult.get("value")
if (pageType != 'eWebRequest') {
//log.warn("page-type != eWebRequest. page-type = " + pageType)
return
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've made it a little further. I now get an error on this line:
def response = confluenceClient.get(path: 'rest/api/content/' + page.id + '/property/page-type')
2017-08-04 14:05:27,032 ERROR [http-nio-80-exec-273] [onresolve.scriptrunner.confluence.InnerListener] call Event handler failed: event: com.atlassian.confluence.event.events.content.page.PageUpdateEvent file: <inline script> -- url: /pages/doeditscaffold.action | page: 24182814 | traceId: fcc54e7651b2acea | userName: er16568 | referer: http://confluence/pages/editscaffold.action?pageId=24182814 | action: doeditscaffold groovyx.net.http.HttpResponseException: Not Found at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263) at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:222) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:164) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.RESTClient.get(RESTClient.java:119) at groovyx.net.http.RESTClient$get.call(Unknown Source) at Script844.run(Script844.groovy:39)
import com.atlassian.confluence.event.events.content.page.PageEvent
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.pages.Page
PageEvent event = event as PageEvent
Page page = event.getPage()
Space space = page.getSpace()
if (space.key != 'eWebProjects') {
log.warn("eWebRequest Form Save Event - this is not the eWebProjects space")
return
}
import groovyx.net.http.Method
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.RESTClient
import groovy.json.JsonBuilder
def clientURL = 'http://confluence/'
def confluenceClient = new RESTClient(clientURL)
def response = confluenceClient.get(path: 'rest/api/content/' + page.id + '/property/page-type')
log.warn("eWebRequest Form Save Event: 2")
def pageType = response.class
log.warn("eWebRequest Form Save Event: 3")
log.warn("eWebRequest Form: page-type = " + pageType)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you ever find a solution? I'm trying to call the Confluence REST API as well to no avail.
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.