{
String dataSource = Settings.getInstance().getSiteInfo(CVUtility.getHostName(super.getServlet().getServletContext())).getDataSource();
AdvancedSearchHome advancedSearchHome = (AdvancedSearchHome) CVUtility.getHomeObject("com.centraview.advancedsearch.AdvancedSearchHome",
"AdvancedSearch");
PrintTemplateHome PTHome = (PrintTemplateHome) CVUtility.getHomeObject("com.centraview.printtemplate.PrintTemplateHome", "Printtemplate");
MailHome mailHome = (MailHome) CVUtility.getHomeObject("com.centraview.mail.MailHome", "Mail");
try {
HttpSession session = request.getSession();
UserObject userObject = (UserObject) session.getAttribute("userobject");
int individualID = userObject.getIndividualID();
DynaActionForm dynaform = (DynaActionForm) form;
String mergeType = (String) dynaform.get("mergetype");
String actionType = null;
if (request.getParameter("actionType") != null) {
actionType = request.getParameter("actionType");
}
int categoryId = this.getCategoryIdFromType(mergeType);
PrintTemplate PTRemote = PTHome.create();
PTRemote.setDataSource(dataSource);
AdvancedSearch remoteAdvancedSearch = advancedSearchHome.create();
remoteAdvancedSearch.setDataSource(dataSource);
String savedsearch1 = "";
String specificentity = "";
String entitysavedsearch = "";
if (mergeType.equals("EMAIL")) {
// collect the Account List and set it to the dynaActionForm.
Mail mailRemote = mailHome.create();
mailRemote.setDataSource(dataSource);
ArrayList accountIDList = mailRemote.getUserAccountList(individualID);
// also adding delegated accounts
accountIDList.addAll(mailRemote.getDelegatedAccountList(individualID));
ArrayList accountList = new ArrayList(); // this, we're sending to the