Calling Save() after editing a Document's properties inside a try block results in the changes being lost.
Document p = new Document(id);
try {
p.getProperty("estado").Value = cReq["payment_status"];
p.getProperty("txn_id").Value = cReq["txn_id"];
p.getProperty("payment_date").Value = cReq["payment_date"];
p.getProperty("mc_gross").Value = cReq["mc_gross"];
Log.Add(LogTypes.Custom, -1, string.Format("Document's value before saving: '{0}'", p.getProperty("estado").Value.ToString()));
p.Save();
Log.Add(LogTypes.Custom, -1, string.Format("Document's value after saving: '{0}'", p.getProperty("estado").Value.ToString()));
}
catch(Exception ex)
{
Log.Add(LogTypes.Custom, -1, string.Format("Exception caught: {0}", ex.ToString()));
}
The output for this code is:
Document's value before saving: 'Completed'
Document's value after saving: ''
The solution I've found is to access one of the properties after the try-catch block and then call Save(). Accessing a property before saving is crucial, otherwise the changes are still lost.
Working code:
Document p = new Document(pedido.Id);
try {
p.getProperty("estado").Value = cReq["payment_status"];
p.getProperty("txn_id").Value = cReq["txn_id"];
p.getProperty("payment_date").Value = cReq["payment_date"];
p.getProperty("mc_gross").Value = cReq["mc_gross"];
Log.Add(LogTypes.Custom, -1, string.Format("Document's value inside try block: '{0}'", p.getProperty("estado").Value.ToString()));
}
catch (Exception p_ex){
Log.Add(LogTypes.Custom, -1, string.Format("Exception caught: {0}", ex.ToString()));
}
Log.Add(LogTypes.Custom, -1, string.Format("Document's value after try block: '{0}'", p.getProperty("estado").Value.ToString()));
p.Save();
Log.Add(LogTypes.Custom, -1, string.Format("Document's value after saving: '{0}'", p.getProperty("estado").Value.ToString()));
Which results in
Document's value inside try block: 'Completed'
Document's value after try block: 'Completed'
Document's value after saving: 'Completed'
Any idea what's going on? This discovery also resolved my original problem in this thread. While debugging I came across this discussion, which seems somewhat related.
v6.0.2 Calling Document.Save() inside try block discards changes
Calling Save() after editing a Document's properties inside a try block results in the changes being lost.
The output for this code is:
The solution I've found is to access one of the properties after the try-catch block and then call Save(). Accessing a property before saving is crucial, otherwise the changes are still lost.
Working code:
Which results in
Any idea what's going on? This discovery also resolved my original problem in this thread. While debugging I came across this discussion, which seems somewhat related.
is working on a reply...