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

Retrieve all objects attached to this page and of class XWikiComments

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

[com.xpn.xwiki.api.Object@775ea56b, com.xpn.xwiki.api.Object@66be5106, com.xpn.xwiki.api.Object@58b9959c, com.xpn.xwiki.api.Object@d6246, com.xpn.xwiki.api.Object@6eaee1b0, com.xpn.xwiki.api.Object@1b632295, com.xpn.xwiki.api.Object@973723f, com.xpn.xwiki.api.Object@7a518af1, com.xpn.xwiki.api.Object@7f7912f3, com.xpn.xwiki.api.Object@65cb50e6]

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