I have Confluence Data Center 9.2.19 and ScriptRunner 9.33.0. I am trying to generate a Display SpacesView Report like shown here: https://www.scriptrunnerhq.com/help/example-scripts/spaces-view-report-onPrem
This script is for older version, it appears, and when I attempt to run it, I get no script errors, but after running it, I see this: Cannot invoke method getAt() on null object (see screen attached). Can someone help me fix this so it will run? Thank you!
Hola Kathy,
@Viswanathan Ramachandran's suggestion to check the logs and test the endpoint is a good place to start, but the exact error may be caused by a null value in the example script rather than the REST endpoint itself.
The ScriptRunner example includes this line:
td { p(space?.lastViewedAt[0..9]) }
If one of the spaces doesn’t have a lastViewedAt value, Groovy tries to apply [0..9] to null, which results in a Cannot invoke method getAt() on null object error.
Try replacing it with:
td { p(space?.lastViewedAt ? space.lastViewedAt.take(10) : "Never viewed") }
I’d also make the returned list null-safe:
def activityBySpace = result?.activityBySpace ?: []
That should prevent the script from failing when a space hasn’t been viewed or when the response doesn’t contain the expected list.
It would still be worth logging the response immediately after the request so you can see exactly what Confluence is returning:
log.warn("Analytics response: ${response.body()}")
It appears to have been written and tested against older Confluence and ScriptRunner versions, so Confluence 9.2.19 may require additional changes. Confluence 9 introduced several platform and REST changes, but since this script is calling the internal confanalytics endpoint, I wouldn’t assume the endpoint changed until you confirm what it returns.
Thanks,
James
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.