Tags:
not added yet
Custom email processing using scriptsStarting from codeBeamer 7.8 users can add a custom Groovy or Javascript script to process emails arriving to an email address and do practically anything with that, for example create new issues, comments and whatnot. To configure just create a new email inbox, and at the bottom of page add your Groovy or Javascript script. This is how it looks on the UI:
The script entered here will be processed regurarly (when emails are polled) and script will be called once for every incoming email. The scripts' scope will contain:
Few tips:
An example groovy script which creates new Work items in a tracker is here: import java.util.regex.*; import com.intland.codebeamer.persistence.dto.*; import com.intland.codebeamer.persistence.dto.base.*; import com.intland.codebeamer.persistence.dao.*; import com.intland.codebeamer.persistence.util.ArtifactPlusContent; import com.intland.codebeamer.remoting.ArtifactType; import com.intland.codebeamer.remoting.DescriptionFormat; import com.intland.codebeamer.manager.*; import com.intland.codebeamer.controller.importexport.*; import org.apache.commons.lang3.*; import com.intland.codebeamer.text.html.*; import com.intland.codebeamer.manager.util.*; logger.info("I'm a groovy script, processing " + email); // id of Leads tracker on cb.com leadTrackerId = 94520 trackerDao = applicationContext.getBean(TrackerDao.class); trackerItemManager = applicationContext.getBean(TrackerItemManager.class); item = new TrackerItemDto(); leadsTracker = trackerDao.findById(leadTrackerId); item.setTracker(leadsTracker); // read custom fields in "Leads" tracker // using a helper class to access fields by name fieldAccessor = new com.intland.codebeamer.text.excel.FieldAccessor(applicationContext); fieldAccessor.setUser(user); def setField(issue, fieldName, value) { field = fieldAccessor.getFieldByName(issue, fieldName); if (field != null) { field.setValue(issue, value); } else { logger.warn("Can not find field <" + fieldName +"> on " + issue); } }; def getEmailValue(text, regexp, defaultValue) { p = Pattern.compile(regexp); matcher = p.matcher(text); found = defaultValue; if (matcher.find()) { found = matcher.group(1); found = StringUtils.trimToNull(found); } logger.info("Found <" + found +"> for regexp <" + regexp +">"); if (StringUtils.isBlank(found) || "--".equals(found)) { found = defaultValue; } return found; } subject = email.subject; message = ""; if (subject.contains("CB New Account") && (subject.contains("saas.codebeamer.com") || subject.contains("codebeamer.com"))) { // a new account is created on saas html = email.getHtmlParts().get(0).getBody(); txt = HtmlCleaner.htmlToText(html); // convert the HTML to plain text to extract data from there logger.info("Cleaned HTML to <" + txt +">") firstName = getEmailValue(txt, "(?m)First Name(.*?)$", "--"); lastName = getEmailValue(txt, "(?m)Last Name(.*?)$", "--"); email = getEmailValue(txt, "(?m)Email.*?\<mailto:(.*)\>.*?$", "--"); company = getEmailValue(txt, "(?m)Company(.*)$", email); country = getEmailValue(txt, "(?m)Geo-Location(.*?),", "--"); setField(item, "First name", firstName); setField(item, "Last name", lastName); setField(item, "E-Mail", email); setField(item, "Company", company); setField(item, "Country", country); setField(item, "Lead Source", "Trial registration"); desc = subject +" "; desc += "Country:" + country +" "; item.description = desc; } else { to = email.getHeader("to"); if ("wordpress@intland.com".equals(to)) { txt = email.getPlainTextParts().get(0).getBody(); logger.info("Processing email text:<"+ txt +">"); email = getEmailValue(txt, "(?m)Email(.*)$", "--"); if (! email.equals("--")) { firstName = getEmailValue(txt, "(?m)First Name(.*)$", "--"); lastName = getEmailValue(txt, "(?m)Last Name(.*)$", "--"); company = getEmailValue(txt, "(?m)Company(.*)$", email); phone = getEmailValue(txt, "(?m)Phone(.*)$", "--"); country = getEmailValue(txt, "(?m)Geo-Location(.*?),", "--"); setField(item, "First name", firstName); setField(item, "Last name", lastName); setField(item, "E-Mail", email); setField(item, "Company", company); setField(item, "Phone", phone); setField(item, "Country", country); setField(item, "Lead Source", "Trial registration"); desc = subject +" "; desc += "Country:" + country +" "; message = getEmailValue(txt, "(?m)(?s)Message:(.*)", ""); if (! StringUtils.isBlank(message)) { desc += " Message: " + message +" "; } item.description = desc; } } else { item = null; } } if (item != null) { try { logger.warn("Creating a new item" + item); trackerItemManager.create(user, item, null); logger.warn("Created item:" + item); } catch (Throwable th) { err = th.getMessage(); logger.info("Failed to create item:" + item, th); if (err.contains("same email") || err.contains("already exists")) { // if this is a VetoException with "Lead #1234 with same email already exists!" because duplicate emails found // and thrown by CodebeamerComTrackerItemListener, then add the subject as comment to the issue Pattern issueIdPattern = Pattern.compile("\#(\d*)"); matcher = issueIdPattern.matcher(err); if (matcher.find()) { issueId = Integer.valueOf(matcher.group(1)); logger.warn("Adding comment to issue #" + issueId +", subject:<" + subject +">"); ArtifactDto comment = new ArtifactDto(); comment.setOwner(user); comment.setDescriptionFormat(DescriptionFormat.WIKI); comment.setDescription(subject +" " + message); Date date = new Date(); comment.setCreatedAt(date); comment.setLastModifiedAt(date); comment.setTypeId(Integer.valueOf(com.intland.codebeamer.remoting.ArtifactType.ISSUE_ATTACHMENT)); List<ArtifactPlusContent> arts = Arrays.asList(new ArtifactPlusContent(comment, null)); trackerItemManager.addAttachments(user, issueId, arts, null, new ActionData(null)); } } } } |
Fast Links
codebeamer Overview codebeamer Knowledge Base Services by Intland Software |
This website stores cookies on your computer. These cookies are used to improve your browsing experience, constantly optimize the functionality and content of our website, furthermore helps us to understand your interests and provide more personalized services to you, both on this website and through other media. With your permission we and our partners may use precise geolocation data and identification through device scanning. You may click accept to consent to our and our partners’ processing as described above. Please be aware that some processing of your personal data may not require your consent, but you have a right to object to such processing. By using our website, you acknowledge this notice of our cookie practices. By accepting and continuing to browse this site, you agree to this use. For more information about the cookies we use, please visit our Privacy Policy.Your preferences will apply to this website only.