ContentService and time tags

Ulrich Lazar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 23, 2024

I am trying to create new pages from a template via the ContentService Interface + ScriptRunner and have run into the following problem:

Using the following code (the relevant bits of my ServiceHelper class):

import com.atlassian.confluence.api.service.content.ContentService
import com.onresolve.scriptrunner.runner.customisers.PluginModule

@PluginModule
ContentService contentService
String getPageBodyById(String pageid) {
return contentService.find(
new Expansion(Content.Expansions.BODY, new Expansions(new Expansion("storage"))),
new Expansion(Content.Expansions.ANCESTORS),
new Expansion(Content.Expansions.SPACE),
new Expansion(Content.Expansions.VERSION),
)
.withId(ContentId.of(Long.parseLong(pageid)))
.fetchOrNull()
.getBody()
.get(ContentRepresentation.STORAGE)
.getValue()
}
This works pretty well to extract the PageBody of most pages, but when using this on a page with a date macro (nothing else apart from the title) i get the following error message:

2024-08-23 10:25:45,234 ERROR [com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint]: ************************************************************************************* 2024-08-23 10:25:45,234 ERROR [com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint]: Script console script failed: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '<p><time datetime="2024-08-23" /> </p>' with class 'java.lang.String' to class 'com.atlassian.confluence.api.model.content.Content' at util.ServiceHelper.getPageBodyById(ServiceHelper.groovy:51) at util.ServiceHelper$getPageBodyById.call(Unknown Source) at Script7.run(Script7.groovy:3)

So... is ContentService unable to parse a <time> tag; is it a ScriptRunner issue? Any ideas/advice would be appreciated since google is less than forthcoming.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.11
TAGS
AUG Leaders

Atlassian Community Events