Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


How to get all drafts for user using scriptrunner


I'm trying to get the list of drafts for given user, using groovy script in scriptrunner console.

Here is the code:


import com.atlassian.confluence.pages.DraftManager

import com.atlassian.sal.api.component.ComponentLocator

import com.atlassian.user.User

import com.atlassian.confluence.user.UserAccessor

def userManager = ComponentLocator.getComponent(UserAccessor)

def user = userManager.getUserByName("test_user")

def draftManager =ComponentLocator.getComponent(DraftManager)

def allDrafts = draftManager.findDraftsForUser(user)

return allDrafts

The problem is the result of this script is empty list, though this user has one draft. The result is the same for other users. 

I also tried to use getDraft(long draftId) method, using the correct ID for existing draft, but I keep receiving null as the result. Seems like I can't access any draft in Confluence using DraftManager. 

Any ideas why this happens and how can I access list of  user`s drafts?


1 answer

0 votes
Ram Kumar Aravindakshan _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.
Jul 05, 2023

Hi @Elena Oleksenko

I'm not sure if your approach will work as expected. However, you can try the sample code below:-

import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)

def spaces = spaceManager.allSpaces
def list = []
def currentUser = userAccessor.getUserByName('admin')

spaces.each{ space ->
def pages = pageManager.getPages(space, true)

pages.each{ page ->
if(page.DRAFT == 'draft' && page.creatorName == {
def type = page.type
def date = page.lastModificationDate
list << [, page.creatorName, page.title, type, date]

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events