Script works in Velocity but not in Groovy (xwiki.exists() and others)

Instead of:

You could write:

#set($docu = $xwiki.getDocument($docuSpace)) 
#if (!$doc.isNew())
  ## The doc exists
...

The reason it fails is because you’re passing a Document object to exists() but it accepts a String or a DocumentReference…

So if you want to use it, you’d write:

#set($docExists = $xwiki.exists($docuSpace))

But better use what I’ve shown above, it’s more efficient.

2 Likes