Hello community,
I created a script allowing to inherit the labels of a page to all its descendants. But I find the process complicated (nested loops) and would like to simplify it. Is it possible to use another method than labelManager.addLabel to simultaneously add multiple labels to the same page?
Thank you in advance for your help !
Hi @Florent R_
ScriptRunner has a built-in script, where you can add, delete or rename labels in bulk.
If you want to do this in a script, then you need to hack a little bit. Let me know if you need help.
Regards, Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I will try it on my instance, but because it's a bit of a hack, I need some free time :-)
Perhaps I can look at it this week, but not sure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Florent R_
I did some testing, but this built-in script is too hard for me. I couldn't manage it.
I stuck with the CQLSearchUtils...
But you can try, here is what I got.
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.core.ContentEntityManager
import com.atlassian.confluence.api.service.search.CQLSearchService
import com.onresolve.scriptrunner.canned.confluence.utils.CQLSearchUtils
import com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrors
import com.onresolve.scriptrunner.canned.confluence.admin.model.ManageLabelsCommand
import com.atlassian.confluence.labels.LabelManager
import com.atlassian.user.UserManager
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.user.ConfluenceUser
import com.onresolve.scriptrunner.canned.confluence.admin.Actions
import com.onresolve.scriptrunner.canned.confluence.admin.Locations
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import org.apache.log4j.Level
import org.apache.log4j.Logger
import java.util.LinkedHashMap
import com.onresolve.scriptrunner.canned.confluence.admin.ManageLabels
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
log.setLevel(Level.INFO)
def pageManager = ComponentLocator.getComponent(PageManager)
def userManager = ComponentLocator.getComponent(UserManager)
def labelManager = ComponentLocator.getComponent(LabelManager)
def cqlSearchService = ScriptRunnerImpl.getOsgiService(CQLSearchService)
ContentEntityManager contentEntityManager = ComponentLocator.getComponent(ContentEntityManager)
CQLSearchUtils cqlSearchUtils = new CQLSearchUtils(cqlSearchService, contentEntityManager, pageManager)
List<Long> targetPageIds = [115082958]
ManageLabels manager = new ManageLabels(labelManager, pageManager, cqlSearchUtils, userManager)
ManageLabelsCommand command = new ManageLabelsCommand()
command.setAction(Actions.ADD)
command.setLocations(Locations.CUSTOM)
command.setTargetPageIds(targetPageIds)
command.setLabels("test")
command.setNewLabelName("newlabel")
SimpleBuiltinScriptErrors errorCollection = (SimpleBuiltinScriptErrors) manager.validate(command, false)
if(errorCollection.hasAnyErrors()) {
log.warn("Error while changing Author: $errorCollection")
result = errorCollection.getErrors()
} else {
result = "OK"
}
log.debug(result)
Perhaps, you find the problem :)
Let me know if you could manage it.
Regards, Dominic
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Dominic, but where did you found the source code of the build-in script ?
I will try anyway.
Have a nice day :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I downloaded the JAR of the scriptrunner and decoded the class files...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Dominic Lagger , I tried what you said but i'm too newbie in coding. I will postpone that and come back at it later.
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.