Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,316
Community Members
 
Community Events
165
Community Groups

How to access ContentService or ContentPropertyService via ScriptRunner

Hi,

I'm hoping someone can suggest how to achieve this. I want to use the ContentProperty to store some values for a Confluence page, but can't get a handle on either the ContentService or the ContentPropertyService.

 

I'm using Confluence 7.10.2 and ScriptRunner 6.21.0.

I can get an instance of both services via

@Field ContentService contentService = ComponentLocator.getComponent(ContentService, 'apiContentService');

@Field ContentPropertyService contentPropertyService = ComponentLocator.getComponent ContentPropertyService;

using this, I can successfully create and add a new property via contentPropertyService.create( myNewProperty )

however I'm unable to use .find to access the ContentPropertyFinder as

ContentId contentId = ContentId.of(pageId)

def found = contentPropertyService.find().withContentId(contentId).fetchOne();

groovy.lang.MissingMethodException: No signature of method:  com.sun.proxy.$Proxy260.withContentId() is applicable for argument types: (com.atlassian.confluence.api.model.content.id.ContentId) values: [ContentId[id=19071593}]

And I have a similar issue with ContentService

def page = contentService.find().withId(ContentId.valueOf(pageId as String)).fetchOneOrNull();

which crashes out in a similar manner

groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy217.withId() is applicable for argument types: (com.atlassian.confluence.api.model.content.id.ContentId) values: [ContentId{id=19071593}].

Possible solutions: with(groovy.lang.Closure), with(boolean, groovy.lang.Closure), wait(), find(), wait(long), find([Lcom.atlassian.confluence.api.model.Expansion;)

If I try and call .find with null or an Expansion, I get

java.lang.IllegalArgumentException: interface com.atlassian.confluence.api.service.content.ContentService$ContentFinder is not visible from class loader

 

I believe my issue is due to Spring/autowire and Groovy's proxy getting in the way of each other but I'm at a loss as to how to resolve this.

1 answer

1 accepted

1 vote
Answer accepted

For anyone else who has this issue, the answer appears to be to explicitly set the Expansions, which where trial-and-error.

 

def found = contentPropertyService.find(new Expansion('content'), new Expansion('version'))
.withPropertyKey('my-key')
.withContentId(pageId)
.fetch()

found.get().value

does the trick

what is propertyKey? is it the space key?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Confluence: Where work and wellness meet

Feeling overwhelmed by the demands of work and life? With a 25% increase in the prevalence of anxiety and depression worldwide during the pandemic, for most of us, it’s a resounding yes . 🙋‍♀️ ...

732 views 5 21
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you