/* bsf newChildEmail.js 5.2 Template for relation trigger to send email for new child CRs */ importPackage(Packages.com.telelogic.cs.api); // Script specific global variables const script_name = 'newChildEmail.js'; const log_header = "[BSF " + script_name + "] "; var args = bsf.lookupBean('args'); var event = bsf.lookupBean('event'); var change = bsf.lookupBean('api'); var log = bsf.lookupBean('log'); // Ensure that script is running in the expected situation. // This is optional and only to take care of accidental misconfiguration in the lifecycle editor. if (event.triggerType != "relation") { log.warn(log_header + "Script " + script_name + " must not be run as " + event.triggerType + " trigger!"); } else if (event.isPreTrigger()) { log.warn(log_header + "Script " + script_name + " must not be run as pre trigger!"); } else if (!event.isCreate()) { log.warn(log_header + "Script " + script_name + " must not be run as delete trigger!"); } else { // Identify trigger log.info(log_header + "Relation '" + event.name + "'" + " was created from CR '" + event.fromObjectId + "'" + " to CR '" + event.toObjectId + "'"); // Fetch some additional child CR attributes var childCR = change.getAttributes(event.triggerUser.token, event.toObjectId, [ "problem_synopsis", "crstatus", "create_time" ]); log.info(log_header + "Title of new child CR is: " + childCR.get("problem_synopsis").stringValue); log.info(log_header + "Status of new child CR is: " + childCR.get("crstatus").stringValue); log.info(log_header + "Create time of new child CR is: " + childCR.get("create_time").dateValue); // Add here your code to send email... }