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@cb6e1c8

Retrieve all objects attached to this page and of class XWikiComments

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

[com.xpn.xwiki.api.Object@11722c53, com.xpn.xwiki.api.Object@5ebc0617, com.xpn.xwiki.api.Object@a340098, com.xpn.xwiki.api.Object@5c130063, com.xpn.xwiki.api.Object@637e92ce, com.xpn.xwiki.api.Object@ad8456a, com.xpn.xwiki.api.Object@7cb537b5, com.xpn.xwiki.api.Object@5d5c8c09, com.xpn.xwiki.api.Object@66edd2c1, com.xpn.xwiki.api.Object@7a7b1b2]

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