Heads Up :
The post you are writing will appear in a public forum. Please ensure all content is appropriate for public consumption. Review the employee guidelines for the community here.
Created by: Dipika Gupta on 26-07-2013 10:45:04 AM Hi ,
I am new to Customization of elements using java code and not at all great at java I have a custom element which is sending email and capturing any error but just adding it to the log . I want to capture this error as element data so that I can playback an error message to caller and ask him to try again. Can you please guide me where and what to put the code for setting the error captured as element data.
private void sendAttachment(String from, String to, String subject, String text, String Attachment, String Filename, ActionElementData actionData) { Properties props = new Properties(); props.put("mail.smtp.host", "ustu-zone.relay.testing.com"); props.put("mail.smtp.port", "25"); String fileAttachment = Attachment; Session session = Session.getInstance(props, null); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(text); Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); messageBodyPart = new MimeBodyPart(); javax.activation.DataSource source = new FileDataSource(fileAttachment); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(Filename); multipart.addBodyPart(messageBodyPart); message.setContent(multipart); Transport.send(message); actionData.addToLog("Email sent to", to); } catch(Exception e) { actionData.addToLog("Failed to Send Email", ""); actionData.addToLog("Error", e.toString()); } } }
Subject: RE: How to set element data in custom java code Replied by: Hemal Mehta on 26-07-2013 11:17:23 AM There are different ways to do it. In your catch error block you can set something like: catch(Exception e) { actionData.addToLog("Failed to Send Email", ""); actionData.addToLog("Error", e.toString()); //Define this string before returnStatus=”error”; } actionData.setElementData("returnStatus",returnStatus); Check this returnStatus after the action element and play to the caller what you want. Other way you can do is to implement this as a decision element and define the exit state for error, success etc and branch out and play the appropriate message for error to the caller. Hemal
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: