Change subject on ticket, reflected in reply template?

I got a customer who would like to change the subject on request coming from a certain sender and have this reflected in the subject line on the reply sent back. For testing, I put together a simple script and attached it a an email filter. Changing the subject on the request works fine, but I cannot get the subject on the reply to reflect this change..

Is this even achievalbe?

RE: Change subject on ticket, reflected in reply template?

Hi,

What is probably happening is that change of subject is executed after reply template is sent. One way of accomplishing this would be to edit your email filter to "block auto reply" and instead send from your script. 

Ex: 

Ticket t;
if(t.load(getVariable("ticketId").toInteger()))
{
  t.setValue("title", "My new Ticket title");
  t.save();

  //Send Auto Reply - first get id of reply template
  String filterId = t.getValue("filter_id");
  String rtId;
  SearchEngine se;
  se.addField("mail_in_filter.reply_template_id");
  se.addCriteria("mail_in_filter.id", "equals", filterId);
  if(se.select() > 0)
    rtId = se.getField(0);
  
  if(rtId != "")
  {
    ReplyTemplate rt;
    rt.load(rtId.toInteger());
    Parser p;
    t.toParser(p);
    
    Email email;
    email.setValue("from", t.getMailFrom());
    email.setValue("subject", p.parseString(rt.getSubject(0)));
    email.setValue("bodyHtml", p.parseString(rt.getHtmlBody(0)));
    email.setValue("to", getVariable("customerEmail"));
    email.send();
  }
}
Av: Michel Krohn-Dale 29. sep 2020

RE: Change subject on ticket, reflected in reply template?

Perfect, thanks!

Av: Patrik Larsson 29. sep 2020