Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John 10 posts 161 karma points
    Apr 03, 2013 @ 11:59
    John
    0

    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.

    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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies