Today we will see the set function
Requirements :
- XWiki classes
- XWiki Objects
- createNewObject / newObject
- use
We have seen yesterday how to create an object. Today, we will see how to set values by using the function Document.set(). You've seen, we can use "set" with the combination of "use", but he can also be used without. The function will search the first object with this fieldname and set the value.
Prototype in Groovy :
Document.set("fieldName", "value")
Example : We will check if an object Comment exist in the current document. If no, we create it. After, we will set all his values, and save the document.
#if (!$doc.getObject("XWiki.XWikiComments"))
$doc.createNewObject("XWiki.XWikiComments")
Object Added
#end
$doc.set("author", "Jeremi")
$doc.set("date", "14/10/2042 00:00:00")
$doc.set("comment", "This is my first comment using the use() function")
$doc.set("author", "Jeremi")
$doc.save()
Object saved
the newObject / createNewObject function
Requirements :