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()
}
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.