Copied to clipboard

Flag this post as spam?

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


  • Josh Olson 79 posts 207 karma points
    Jan 07, 2014 @ 10:55
    Josh Olson
    1

    U7 Members: Member custom property saving mirage

    Using Umbraco 7.0.1

    I have members with a bunch of custom properties and I am trying to get/set those properties in my code. It almost works but it seems as though I am missing something, probably simple. Here is what I do:

    if (IsPost)
    {                        
         var currentComments = member.getProperty("comments").Value.ToString();
         var addComments = Request["addComment"];
    
         var newComments = String.IsNullOrEmpty(currentComments) 
              ? @currentMember.Text + " [" + DateTime.Now.ToString("dd MMM yy - HH:mm").ToUpper() + "] - " + addComments
              : currentComments + "\n" + @currentMember.Text + " [" + DateTime.Now.ToString("dd MMM yy - HH:mm").ToUpper() + "] - " + addComments;
    
           member.getProperty("comments").Value = newComments;
           member.Save();
    }
    

    and this is the part of the modal window that is used to add comments

    <div class="modal-body">
         <form id="addCommentForm" method="post" role="form">
    
              <h4>Comments</h4>
              <textarea class="form-control input-sms" rows="3"  disabled="disabled">@comments</textarea>
    
              <h4>Add a comment</h4>
              <textarea id="addComment" name="addComment" class="form-control" rows="1"></textarea>
    
         </form>
    </div>
    
    <div class="modal-footer">
         <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
         <input id="addCommentSubmit" type="submit" class="btn btn-primary" value="Add comments" />
    </div>
    
    <script>
         $('#addCommentSubmit').on('click', function (e) {
              e.preventDefault();
              $('#addCommentForm').submit();
         });
    </script>
    

    Now, here is where it gets funny. This works. Sort of. When I enter text into the #addComment textarea and submit it, it appears in the textarea in the backend as expected and in the appropriate textarea on the frontend, but, there must be a cached xml file or something because if I reload the page on the frontend, the newly submitted text is now gone. It still appears in the backend, just no longer on the frontend.

    Here is the really goofy bit... if I go to the backend and navigate to the member, like I said, I can see that the newly submitted text is there, and I press 'Save'... it fixes things. Everything now appears on the frontend properly.

    Something is happening when I press 'Save' in the backend that is not happening when I call member.Save(). Any ideas?

    Cheers!

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 07, 2014 @ 11:19
    Jeroen Breuer
    0

    I always do it like this:

    member.Save();
    member.XmlGenerate(new XmlDocument());

    Maybe that helps.

    Jeroen

  • Josh Olson 79 posts 207 karma points
    Jan 07, 2014 @ 11:32
    Josh Olson
    0

    I did try that also (I guess I should have mentioned it) but it did not have any effect.

    For whatever reason I generally have not used member.XmlGenerate(new XmlDocument()) because it has always worked for me without, and you know what they say about things not being broke... but I probably should be using it.

    Any other suggestions?

  • Jonathan Saxon 59 posts 86 karma points
    Jan 07, 2014 @ 17:12
    Jonathan Saxon
    0

    I have the same issue after upgrading to 7.0.1, also I have noticed if you force application pool to recycle I can then retrieve the property any ideas.

  • Josh Olson 79 posts 207 karma points
    Jan 08, 2014 @ 08:46
    Josh Olson
    0

    I am wondering if this is an 'undocumented feature' that needs fixing in the core, or if there is simply a new step that is needed to make this function as it has in the past? I am 50% (+- 49%) sure that it is a matter of 'refreshing' an xml document somewhere, which the backend save appearently causes but the member.Save() does not, and while Jeroen's proposed solution seems like it should work for this, at least in my case it did not.

  • Jonathan Saxon 59 posts 86 karma points
    Jan 08, 2014 @ 10:29
    Jonathan Saxon
    0

    Josh unfortunately it didnt work for me either, I am pretty sure this worked in 7.0.0 as well so guessing something must of changed.

  • Per Ploug 865 posts 3491 karma points MVP admin
    Jan 08, 2014 @ 15:13
    Per Ploug
    1

    Seems like a bug in 7.0.1 - has this been reported on issues.umbraco.org ? - if not, could you report and refer to this thread, then I'll assign it to the 7.0.2 release

  • Josh Olson 79 posts 207 karma points
    Jan 08, 2014 @ 15:36
    Josh Olson
    1

    Issue added to tracker: U4-4005.

    Thanks Per!

  • Mikkel Johansen 116 posts 292 karma points
    Jan 10, 2014 @ 07:59
    Mikkel Johansen
    0

    Looks like it everytime you use member.Save(). Not only when changing custom properties.

    I have tried to test it - see code below. First I get a Member and outputs it. Then changes Login and EMail, and saves the member. Then I get the member again and outputs it. But the properties is the same . Looking in the back-end the changes is visible.

    I have added this observation to the issue tacker U4.4005,

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using umbraco.cms.businesslogic.member
    @using Member = umbraco.cms.businesslogic.member.Member

    @{
    Layout = null;

    // Remember to create Member in Backend
    // Member: Login = test, E-mail = [email protected]

    Member m = Member.GetMemberFromEmail("[email protected]");
    @ShowMember(m)

    m.LoginName = "Test1234";
    m.Email = "[email protected]";

    m.Save();

    Member testMember = Member.GetMemberFromEmail("[email protected]");
    @ShowMember(testMember)
    }

    @helper ShowMember(Member member)
    {
    <p>
    Name: @member.Text<br />
    LoginName: @member.LoginName<br />
    E-mail: @member.Email<br />
    </p>
    }
  • Josh Olson 79 posts 207 karma points
    Jan 10, 2014 @ 08:36
    Josh Olson
    0

    Thanks Mikkel, that confirms exactly what I see happening. I never thought to test it with non-custom properties, but it looks like they are not immune also. -Josh

  • Josh Olson 79 posts 207 karma points
    Jan 21, 2014 @ 12:51
    Josh Olson
    0

    I just upgraded to 7.0.2 and I can confirm that the bug is now fixed. Thanks to all!

Please Sign in or register to post replies

Write your reply to:

Draft