Get custom properties from new member when using MemberService.Saved event
I want to send a notification email when a new member has been created in Umbraco 6.2.2. I'm using the MemberService.Saved event to accomplish this. To determine if the MemberService.Saved event has been fired by a new entity I'm using the following extension method:
foreach (var member in e.SavedEntities)
{
var dirty = var dirty = (IRememberBeingDirty)member;
if (dirty.WasPropertyDirty("Id"))
{
// send notification email
}
}
However, I'm having trouble accessing the member's custom properties. I've tried member.GetValue("customPropertyName"), and member.Properties["customPropertyName"].Value, and I've even tried accessing the custom properties through the obsolete API:
var m = umbraco.cms.businesslogic.member.Member.GetMemberFromLoginName(member.Username);
m.getProperty("customPropertyName").Value;
But for some reason every custom property returns a null value. Does anyone have any idea why? When using this code on saving an existing member the custom properties do return the proper values.
The properties I'm trying to retrieve are all Textstring or True/false. And yes, I can see the values in the backoffice. Again, the properties aren't available in the MemberService.Saved event when the event is triggered by saving a new member, the properties are available when the event is triggered by saving/updating an existing member.
@Nikola: Unfortunately not. Instead I've created a task that runs every hour to process new members. This works in our situation, but I realize this won't be an acceptable solution for all situations.
Arjan what are your property alias values. They need to be different to the name as Umbraco seems to do a case insensitive match. I have had this problem before. Hope that helps. Charlie.
Also on the member object you create. In the watch window you should be able to see the properties on that object? Are they also null?
I'm using uWebshop and I'm trying to access the properties uWebshop adds to the member type like: customerFirstName, customerLastName, etc. And yes, when I set a watch on the object during debugging the properties are also null.
Nope, I never found a solution. Like I said in one of my previous replies I worked around it by implementing a scheduled task that did some post-processing on new members.
By the way, which version of Umbraco are you using? Are you still on 6.2.x or is this also an issue on 7.x?
I am also stuck here. I created a custom member type in back office and a few properties there.
Now I can access the type in the code but all the properties are coming with null values.
var searcher = Examine.ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
IEnumerable<SearchResult> pagedResults;
var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.And);
IBooleanOperation query = null;
//Build the Examine query
query = searchCriteria.Field("Type", "Agent");
//Get the search result
var results = searcher.Search(query.Compile());
if (results.Count > 0 )
{
foreach (var result in results )
{
AgentViewCMSModel item = new AgentViewCMSModel();
var node = Members.GetById(Convert.ToInt32(result.Fields["id"]));
item.Country = node.GetPropertyValue(item.COUNTRY_PROPERTY_NAME).ToString();
}
}
The problem in above code snippet is, it gets the correct member type records using custom "Type" property's value but gets all the custom properties with "null" values.
Note: I have two custom member Types 'Member' and 'Agents' with different custom properties according to business requirement. is that a problem?
Get custom properties from new member when using MemberService.Saved event
I want to send a notification email when a new member has been created in Umbraco 6.2.2. I'm using the
MemberService.Saved
event to accomplish this. To determine if theMemberService.Saved
event has been fired by a new entity I'm using the following extension method:http://our.umbraco.org/documentation/Reference/Events-v6/determining-new-entity
However, I'm having trouble accessing the member's custom properties. I've tried
member.GetValue("customPropertyName")
, andmember.Properties["customPropertyName"].Value
, and I've even tried accessing the custom properties through the obsolete API:But for some reason every custom property returns a null value. Does anyone have any idea why? When using this code on saving an existing member the custom properties do return the proper values.
What type of property are you trying to retreive. Is it a textbox or something else ?
Also do you see the values for the member in the backoffice.
Dave
The properties I'm trying to retrieve are all Textstring or True/false. And yes, I can see the values in the backoffice. Again, the properties aren't available in the
MemberService.Saved
event when the event is triggered by saving a new member, the properties are available when the event is triggered by saving/updating an existing member.By the way.
Since your are using 6.2.2 you can also check if a member is new by using : var isNew = entity.IsNewEntity();
Dave
What result do you get when you member.GetProperty("customProperty").Value ?
Dave
Null values.
Hi Arjan!
Have you found a solution?
Cheers, Nikola
@Nikola: Unfortunately not. Instead I've created a task that runs every hour to process new members. This works in our situation, but I realize this won't be an acceptable solution for all situations.
Yeah, that won't work for my situtation :) But thanks anyway.
Arjan what are your property alias values. They need to be different to the name as Umbraco seems to do a case insensitive match. I have had this problem before. Hope that helps. Charlie.
Also on the member object you create. In the watch window you should be able to see the properties on that object? Are they also null?
Charlie :)
I'm using uWebshop and I'm trying to access the properties uWebshop adds to the member type like: customerFirstName, customerLastName, etc. And yes, when I set a watch on the object during debugging the properties are also null.
Got stuck here too.. Did you find a solution?
Nope, I never found a solution. Like I said in one of my previous replies I worked around it by implementing a scheduled task that did some post-processing on new members.
By the way, which version of Umbraco are you using? Are you still on 6.2.x or is this also an issue on 7.x?
I am also stuck here. I created a custom member type in back office and a few properties there.
Now I can access the type in the code but all the properties are coming with null values.
The problem in above code snippet is, it gets the correct member type records using custom "Type" property's value but gets all the custom properties with "null" values.
Note: I have two custom member Types 'Member' and 'Agents' with different custom properties according to business requirement. is that a problem?
any lead will be highly appreciated.
Thanks
ok, it works now. the same code works without any change (I just clean built the solution).
still trying to figure out what happened :)
thanks anyway..
Anybody got the solution for this?
is working on a reply...