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.DraftManagerimport com.atlassian.sal.api.component.ComponentLocatorimport com.atlassian.user.Userimport com.atlassian.confluence.user.UserAccessordef 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?
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.PageManagerimport com.atlassian.confluence.spaces.SpaceManagerimport com.atlassian.confluence.user.UserAccessorimport com.atlassian.sal.api.component.ComponentLocatordef spaceManager = ComponentLocator.getComponent(SpaceManager)def pageManager = ComponentLocator.getComponent(PageManager)def userAccessor = ComponentLocator.getComponent(UserAccessor)def spaces = spaceManager.allSpacesdef 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
It looks like you're new here. Sign in or register to get started.