You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hello,
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?
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 == currentUser.name) {
def type = page.type
def date = page.lastModificationDate
list << [space.name, page.creatorName, page.title, type, date]
}
}
}
list
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,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.