Hello,
I have a customer that wants to enable 'out of office' in Service. They want this auto-reply to be sent when you create a new ticket AND when a new message is created on a existing one.
I have created a trigger on the 'new message on request'-event, which loads up a template and send an auto-reply to whoever is sending in the message. This event works in both scenarios.
The script looks like this:
#setLanguageLevel 3;
Integer ticketId = getVariable("ticketId").toInteger();
Integer messageId = getVariable("messageId").toInteger();
if(ticketId > 0)
{
Parser p;
// Get the ticket
Ticket t;
t.load(ticketId);
t.toParser(p);
Integer customerId = t.getValue("custId").toInteger();
//Get customer linked to the ticket
if(customerId > 0)
{
Customer c;
c.load(customerId);
c.toParser(p);
}
// Load the message and get the correct email-adress to send the auto-reply to
Message m;
m.load(messageId);
String header = m.getValue("emailHeader");
Integer createdBy = m.getValue("createdBy").toInteger();
String mainEmail;
if (header.getLength()<1 && createdBy>1)
{
User u;
u.load(createdBy);
mainEmail = u.getValue("email");
}
else if (header.getLength()>0)
mainEmail = header.after("\nFrom: ").before(":").after("<").before(">");
// Load the template
String body = p.parseString(getReplyTemplateBody(48, true, -1)); //48 = TemplateID for "Julestengt" in the database
// Send the email
Email em;
em.setValue("bodyHtml", body);
em.setValue("to", mainEmail);
em.setValue("from", "es@insight-as.suocrm.com");
em.setValue("subject", "Julestengt!");
em.send();
}
I have 2 questions:
1. Can i do this through a supermacro instead of script? The auto-reply should not be sent to the owner of the request, but whatever email-adress the message/email comes from.
2. When i send an email in on the request i get 2 auto-replies back. If i reply on the request in Service it only send 1 (as it should).
Is there a reason why my trigger is 'triggered' 2 times? This happens in both my onsite test-installation and OnlineCRM.
//Eivind