Event Handler to change property of Member on Created
Hello fellow Umbracians,
I'm running Umbraco 7.2.8 and I need to save some data in a member property (label or textstring) when a new member is created. The following code does not work. The property with alias "certificationID" is not being populated. From the code, you can see I've tried changing the property value two different ways. neither way works. Any ideas? I've not dealt with events or members in Umbraco 7 so maybe I'm missing something? I'm not getting any clues from the console log...
Thanks for the reply! This does not work for me either. I'm not getting any errors, but my text box is still empty... but the fact that it is working for you may mean I've got something else hindering the save?
var member = ApplicationContext.Services.MemberService.GetById(e.Entity.Id);
member.SetValue("cetificationID",12345);
ApplicationContext.Current.Services.MemberService.Save(member);
I've got to be missing something. I tried your code above and I get the same result. I've thrown in some traces to my original and here is what I get:
and below is the debug output:
Property Value line 40: null entity id line 44: 1496 Property Value
line 47: "something" Property Value line 49: "something" A first
chance exception of type 'System.NullReferenceException' occurred in
Umbraco.Core.dll A first chance exception of type
'System.NullReferenceException' occurred in Umbraco.Core.dll A first
chance exception of type 'System.InvalidCastException' occurred in
mscorlib.dll A first chance exception of type
'System.InvalidCastException' occurred in Umbraco.Core.dll The thread
'Lucene Merge Thread #0' (0x2564) has exited with code 0 (0x0).
So it is finding the correct member and it is saving the property value. At line 50 my property value is the value that I've saved, but it doesn't show up on the frontend. I'm also not sure what these 'first chance System.NullReferenceExceptions are all about, but I'm not sure how to get more information on those... any ideas?
Event Handler to change property of Member on Created
Hello fellow Umbracians,
I'm running Umbraco 7.2.8 and I need to save some data in a member property (label or textstring) when a new member is created. The following code does not work. The property with alias "certificationID" is not being populated. From the code, you can see I've tried changing the property value two different ways. neither way works. Any ideas? I've not dealt with events or members in Umbraco 7 so maybe I'm missing something? I'm not getting any clues from the console log...
Hi,
I saved the property this way, maybe this works better:
Thomas,
Thanks for the reply! This does not work for me either. I'm not getting any errors, but my text box is still empty... but the fact that it is working for you may mean I've got something else hindering the save?
Have you set a breakpoint to see if your code really steps into the if-Condition?
I've checked that. I've added tracepoints noting the property value before and after save and they look correct.
Mh, ok. Give this a try:
I've got to be missing something. I tried your code above and I get the same result. I've thrown in some traces to my original and here is what I get:
and below is the debug output:
So it is finding the correct member and it is saving the property value. At line 50 my property value is the value that I've saved, but it doesn't show up on the frontend. I'm also not sure what these 'first chance System.NullReferenceExceptions are all about, but I'm not sure how to get more information on those... any ideas?
Looking into it further, looks like the same issue as described in this post:
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/52676-Add-Member-to-MemberGroup-in-MemberServiceCreated-handler
I think I'm going to have to abandon this and try to solve my problem a different way...
is working on a reply...