How to Add Leads to Lists Programatically | Community
Skip to main content
Level 5
October 16, 2015
Solved

How to Add Leads to Lists Programatically

  • October 16, 2015
  • 4 replies
  • 958 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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#setProperty(java.lang.String, 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. 

4 replies

smacdonald2008
Level 10
October 16, 2015

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.

vdhim23Author
Level 5
October 16, 2015

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();
smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

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#setProperty(java.lang.String, 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. 

smacdonald2008
Level 10
October 16, 2015

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.