Hi, I am writing a script on Scriptrunner that returns a value from a metadata field.
Please tell me how can I update the value of this metadata field using the saveContentMetadataValue method ?
I can not find an example ;(
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.pages.templates.PageTemplateManager
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.setup.settings.SettingsManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.communardo.confluence.metadata.service.MetadataManager
import com.communardo.confluence.metadata.*
@WithPlugin("com.communardo.confluence.metadata")
def pageTemplateManager = ComponentLocator.getComponent(PageTemplateManager)
def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)
def settingsManager = ComponentLocator.getComponent(SettingsManager)
def meta = ScriptRunnerImpl.getOsgiService(MetadataManager)
def sampleSpaceKey = "DRAFT"
def sampleSpace = spaceManager.getSpace(sampleSpaceKey)
def samplePage = pageManager.getPage(561906838)
def ceo = samplePage.getContentEntityObject()
MetadataField sets = meta.loadMetadataFieldByKey("metadatafield.itdoctechwriter",sampleSpace)
DataObject q = meta.loadContentMetadataValue(ceo, sets)
return q
Hi Roman,
so the API tells us to use:
public void saveContentMetadataValue(ContentEntityObject ceo, MetadataField metadataField,
DataObject metadataValue)
You already used the correct method to retrieve the Dataobject from a page. The output shows us that it is an array of Confluence users. What if you try to get a user from confluence and add it to this array and then write it back:
meta.saveContentMetadataValue(ceo, metadataField, yourModifiedUserArray)
This should work.
Thank you.
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.