Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's some code that I recently did to set up some custom profile stuff for a client using the Email Campaign Manager. Granted this code uses some classes specific to ECM, it creates a new user, initializes a profile class and then assigns that profile to the new user. Then it sets some custom properties for the user that was just created. It shows you how to call the profile based on the user as well as assigning a profile to use for that user. This might help or maybe help someone else. </p> <pre><code> public static void Process(List&lt;Subscriber&gt; userItems, Item targetAudienceDefinitionItem) { foreach (Subscriber user in userItems) { // you can also just pass it the id of the target audience as a string Sitecore.Modules.EmailCampaign.TargetAudienceBase target = Sitecore.Modules.EmailCampaign.TargetAudience.FromItem(targetAudienceDefinitionItem); string campaignname = target.ManagerRoot.Settings.CommonDomain; string realUsername = campaignname + "\\" + user.UserName; using (new SecurityDisabler()) { User newUser; if (!Sitecore.Security.Accounts.User.Exists(realUsername)) { // create a new user and assign it to the email domain specified in the manager root item newUser = Sitecore.Security.Accounts.User.Create(campaignname + "\\" + user.UserName, System.Web.Security.Membership.GeneratePassword(8,1)); } else // get back the existing user newUser = User.FromName(realUsername, false); // get back the current user profile UserProfile subscriber = newUser.Profile; // reset the profile to be the profile specified in the manager root subscriber.ProfileItemId = target.ManagerRoot.Settings.SubscriberProfile; subscriber.Save(); // built in properties are set like this subscriber.Email = user.Email; // set custom property value subscriber["Address"] = user.Address; // or long method subscriber.SetCustomProperty("Address", user.Address); subscriber.Save(); // now subscribe the user to the target audience subscriber list target.Subscribe(Contact.FromName(newUser.Name)); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload