Only process a ScriptRunner event for certain pages. Edited

I want to use a ScriptRunner event to only process certain pages. I know how to narrow the page down to the space within the ScriptRunner event code, but I only want to process certain pages within the space. Is there a way when creating pages to designate what I'll call a PageType? So when I create a page, I'd like to give the page a PageType I define and then read that value from Groovy.

To help clarify this a little more, I have a space lets call Projects. Under this I have what I call a "Project" page type and under Project page I have a Request page. I want the ability to define each of these page type and be able to use Groovey to determine what each page type is.

(space) Projects

    - Project 1

        - Request 1

    - Project 2

        - Request 2

1 answer

This widget could not be displayed.
Stephen Deutsch Community Champion Aug 09, 2017

Maybe you could define a label that refers to a specific page type and filter based on that?

I was able to add a Content Property to my pages. My one issue now is how to retrive the Content Property via REST. This is what I have so far but it's not working. I've add log entries to see how far it gets and I get to "eWeb Request Form Event: 2" and then it throws an error on http.get with a Not Found error.

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
}

import groovyx.net.http.HTTPBuilder
//import static groovyx.net.http.ContentType.*
//import groovyx.net.http.ContentType
//import static groovyx.net.http.Method.*
//import groovy.json.JsonSlurper
//import net.sf.json.groovy.JsonSlurper

log.warn("eWeb Request Form Event: 1")
def http = new HTTPBuilder('http://confluence/rest/api/')
log.warn("eWeb Request Form Event: 2")
def pageType
def url = 'content/' + page.id + '/property/page-type/'

http.get(path: url,
contentType : 'application/json'
) { resp, reader ->

println reader
log.warn("eWeb Request Form Event: 3")
//pageType = json
}

log.warn("eWeb Request Form Event: page-type = " + pageType)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

506 views 7 6
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