Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to Add Leads to Lists Programatically

Avatar

Level 5

Hi,

I am trying to create a user that that will be act like a lead same as in Campaign console & want to assign this to List provided. I have created the user using UserManager api.

Session session = resourceResolver.adaptTo(Session.class); User subscriberUser = userManager.createUser(email_id, RandomStringUtils.randomAlphanumeric(20).toUpperCase()); session.save();

But these are not reflecting as Lead in Campaign console, Also want to add this user in the list created say : xyz . Any Idea how can i achieve this programmatically.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Given that you use case is to:

 "send newsletter to the list of users"

and 

"need to set the email property"

Once you create the user -- you can set email using this method:

http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/security/user/Authorizable.html#setPr..., javax.jcr.Value)

Notice that setPropery  method is inherited from interface org.apache.jackrabbit.api.security.user.Authorizable.

Also - use JCR-SQL code to query the child profile node under user too. Then set the email on this node. 

After all the email for all users is set - you can write a server-side OSGi method to email everyone. 

View solution in original post

4 Replies

Avatar

Level 10

Write a custom OSGi service that defines a User class, and a service. You can use JackRabbit User API to perform user tasks - AEM UserManager API is deprecated:

https://helpx.adobe.com/experience-manager/using/developing-aem-osgi-bundles-jackrabbit.html

As you get user data, add the User objects to a List collection object (ie ArrayList), order the collection and then have the service return users within JSON data. 

DO not try to add JSP logic to do this. Keep components thin and make use of OSGi/Java to perform business logic.

Avatar

Level 5

Thanks, Actually my use-case is to send newsletter to the list of users and following the  http://docs.adobe.com/docs/en/cq/5-6-1/wcm/campaigns.html  I seems almost there but here i need to set the email property under profile node. With my servlet code I don't know how it will get set 

Session session = resourceResolver.adaptTo(Session.class); ValueFactory valueFactory = session.getValueFactory(); User subscriberUser = userManager.createUser(email_id, RandomStringUtils.randomAlphanumeric(20).toUpperCase()); subscriberUser.setProperty("cq:authorizableCategory", valueFactory.createValue("mcm")); //subscriberUser.setProperty("email prop under profile node",email_id); Group group = resourceResolver.resolve("/home/groups/m/mygroup").adaptTo(Group.class); group.addMember(subscriberUser); session.save();

Avatar

Correct answer by
Level 10

Given that you use case is to:

 "send newsletter to the list of users"

and 

"need to set the email property"

Once you create the user -- you can set email using this method:

http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/security/user/Authorizable.html#setPr..., javax.jcr.Value)

Notice that setPropery  method is inherited from interface org.apache.jackrabbit.api.security.user.Authorizable.

Also - use JCR-SQL code to query the child profile node under user too. Then set the email on this node. 

After all the email for all users is set - you can write a server-side OSGi method to email everyone. 

Avatar

Level 10

If you want to see an example of using JCR SQL code to get profile node for users -- see this community article:

https://helpx.adobe.com/experience-manager/using/java-swing-applications.html

You can build similar code for your service - then add a method to email users.