v6.0.2 - Document properties need preincrementing instead of postincrementing to get saved
I'm migrating a site from v4.7.0 to v6.0.2 and have found strange behaviour when editing a Document's properties.
Incrementing a "quantity" property in a document only works if it is done with the preincrement operator. The following method should return a number that increments each time it is called (e.g. via /base/namespace/IncrementQuantity/1234)
[RestExtensionMethod(returnXml = false)]
public static string IncrementQuantity(int id)
{
Document doc = new Document(id);
int quantity = Convert.ToInt32(doc.getProperty("quantity").Value);
doc.getProperty("cantidad").Value = quantity++;
doc.Save();
quantity = Convert.ToInt32(doc.getProperty("quantity").Value);
return string.Format("quantity: {0}", doc.getProperty("quantity").Value.ToString());
}
The number never increments though, and stepping through the code shows that as soon as doc.Save() is called the value of quantity is what it originally was. In the backoffice that node's property also stays the same.
Changing the line
doc.getProperty("cantidad").Value = quantity++;
to
doc.getProperty("cantidad").Value = ++quantity;
Fixes the issue and results in the number incrementing each time the page is refreshed.
Was causing the updated quantity to get saved to the database but reverted to the original value in the variable wrappedDocument. On the other hand this code worked fine:
v6.0.2 - Document properties need preincrementing instead of postincrementing to get saved
I'm migrating a site from v4.7.0 to v6.0.2 and have found strange behaviour when editing a Document's properties.
Incrementing a "quantity" property in a document only works if it is done with the preincrement operator. The following method should return a number that increments each time it is called (e.g. via /base/namespace/IncrementQuantity/1234)
The number never increments though, and stepping through the code shows that as soon as doc.Save() is called the value of quantity is what it originally was. In the backoffice that node's property also stays the same.
Changing the line
to
Fixes the issue and results in the number incrementing each time the page is refreshed.
Any clues as to why?
Isnt this a c# thing¨
this will add quantity to doc.getProperty("cantidad").Value and then +1 to quantity
Will add 1 to quantity and then set doc.getProperty("cantidad").Value=quantity
You're right, I can't believe I missed that. My only excuse is my brain was fried from trying to pinpoint the issue I was having :)
The original issue I was having was wrapped in a few layers of abstraction and this was the bare-bones reproducible code I arrived at.
The original issue was updating a C# property that wrapped access to Document.getProperty was behaving strangely, e.g.
Was causing the updated quantity to get saved to the database but reverted to the original value in the variable wrappedDocument. On the other hand this code worked fine:
I've gone back and retested and am not able to reproduce the original issue though, so I don't know what's up.
is working on a reply...