Confluence Adding status field to CQL Edited

Hello,

I am trying to add "Status" field to CQL using Search extractor in Script Runner. However, I am getting it work. I used following code,

import com.atlassian.confluence.pages.Page
import org.apache.lucene.document.Field
import org.apache.lucene.document.TextField


if (searchable instanceof Page) {
Page page = searchable as Page
String status = page.contentEntityObject.getEntity().getProperties().getStringProperty("Status") as String
document.add(new TextField("status", status, Field.Store.YES))
}

 

 

Am I doing anything wrong here?

 

I know there is Atlassian KB for developing a plugin https://developer.atlassian.com/server/confluence/adding-a-field-to-cql/

but I don't want to develop a separate plugin. I believe it should be achievable by ScriptRunner.

 

2 answers

1 accepted

This widget could not be displayed.

Problem is fixed after deleting all cache folders such as plugins-cache, plugins-osgi-cache, plugins-temp, journal and index. Restart the application. Rebuilt Content Index after restart. 

This widget could not be displayed.
Stephen Deutsch Community Champion Jan 15, 2018

Hi Suhas,

it sounds like you're trying to build a SearchExtractor. It seems like you're on the right track, but the line 

String status = page.contentEntityObject.getEntity().getProperties().getStringProperty("Status") as String

could probably be simplified to 

String status = page.getProperties().getStringProperty("Status") as String

since page inherits methods from ContentEntityObject.

 

I think there's three things you need to make sure about:

1. Is the content I'm looking for actually stored in the "status" property?

2. Have I re-built the search index after inserting the script?

3. Do I get results when searching with the recommended syntax ( status : whatever ) in a normal text search?

You may also have to change

document.add(new TextField("status", status, Field.Store.YES))

to

document.add(new StringField("status", status, Field.Store.YES))

and

import org.apache.lucene.document.TextField

to

import org.apache.lucene.document.StringField

Hi Stephen,

Thanks for the inputs.

Yeah, you are right, I will make changes you suggested for simplifying the code.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

733 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you