Groovy


Retrieve the first object (index [0]) among all objects attached to this page and class XWikiComments

obj = doc.getObject('XWiki.XWikiComments')

com.xpn.xwiki.api.Object@18a12ec2

Retrieve all objects attached to this page and of class XWikiComments

objs = doc.getObjects('XWiki.XWikiComments')

[com.xpn.xwiki.api.Object@2526c4e6, com.xpn.xwiki.api.Object@1448eb18, com.xpn.xwiki.api.Object@3f427f0f, com.xpn.xwiki.api.Object@26a3d23b, com.xpn.xwiki.api.Object@4d3f334e, com.xpn.xwiki.api.Object@70416d80, com.xpn.xwiki.api.Object@577c2813, com.xpn.xwiki.api.Object@182b2444, com.xpn.xwiki.api.Object@3859f8c1, com.xpn.xwiki.api.Object@1ada63ce]

Retrieve the author property of all objects attached to this page and of class XWikiComments

objsAuthors = doc.getObjects('XWiki.XWikiComments').author
println objsAuthors

[

First comment

,

Second comment

,

Third comment

,

Fourth comment

,

Fifth comment

,

Sixth comment

,

Seventh comment

,

Fetch an element of a list by index
http://langref.org/all-languages/lists/access/fetch-by-index

,
list = ['One', 'Two', 'Three', 'Four', 'Five']
result = list[2] // index starts at 0
println result
,

Check the code proposed by Vincent here...
http://xwiki.475771.n2.nabble.com/Groovy-equivalents-to-Velocity-examples-td7602776.html

]

Retrieve the author property of the fifth object attached to this page and of class XWikiComments by index

objsAuthor = doc.getObjects('XWiki.XWikiComments')[4].author
println objsAuthor

XWiki.IsabelListaGarcia

Retrieve the author property of the first object attached to this page and of class XWikiComments by index; objs was assigned above!

println objs[0].author

XWiki.RicardoRodriguezFernandez

Tags:
Created by Ricardo Rodríguez Fernández on 2017/02/15 23:05
    
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 7.3 - Documentation