Tiago Rinck Caveden wrote:
Hello Ludovic,
On Sun, May 18, 2008 at 3:58 AM, Ludovic Dubost <[email protected]> wrote:
Archana Mettu wrote:
Having retrieved an object on a page, how can I update some fields of that object and save? Doc.save() saves the document changing its version.... but, doesn't update the object-parameters. What am I missing?
You can use $doc.getObject(classname) to retrieve an object and manipulate it's properties.
I am trying to do exactly that, with a very silly code, and it doesn't work, the value of the property doesn't change. Take a look at the code:
#set($obj = $doc.getObject("Space.MyClass")) #set($obj.accessCounter = $obj.accessCounter + 1) ~~Number of accesses: $obj.accessCounter~~
The value displyed remains the one I defined by editing the object with the object editor, what suggests the second set is not doing what I expected.
Do you have any idea of what am I doing wrong?
1. $obj.accessCounter is not the property value, but is a shorthand for $doc.display(). 2. In order to make the changes persistent, you must also save the document. #set($obj = $doc.getObject("Space.MyClass")) #set($v = $obj.getProperty("accessCounter").value) ## if this is not a number property, you must also parse it ## #set($v = $util.parseInt($v)) #set($v = $v + 1) $obj.set("accessCounter", $v) $doc.save() -- Sergiu Dumitriu http://purl.org/net/sergiu/