Multiple IF statements in New Ticket Creation

I need a method to combine multiple IF statements specifically in the Title of a new ticket. The current Title has this in it to strip out Autotask Ticket numbers. This is used after we already searched for an existing ticket because we’ve had some instances where customers would use Autotask themselves and referenced a ticket on the customer system that wasn’t in ours.

{{#if (before_regex email.subject “/T20[0-9]{6}.[0-9]{4}/” flags=“t”) }} {{before_regex email.subject “/T20[0-9]{6}.[0-9]{4}/” flags=“t”}} {{else}} {{email.subject}} {{/if}}

The issue we have now is if someone sends in email with no subject line that the ticket creation fails. In review of the built in rules, the ticket title has this in it:

{{#if email.subject}}{{email.subject}}{{else}}New email from {{email.from.address}}{{/if}}

To combine the two into one statement, is this the correct syntax?

{{#if (before_regex email.subject “/T20[0-9]{6}.[0-9]{4}/” flags=“t”) }} {{before_regex email.subject “/T20[0-9]{6}.[0-9]{4}/” flags=“t”}}
{{else}} {{#if email.subject}}{{email.subject}}{{else}}New email from {{email.from.address}}{{/if}} {{/if}}

Hi @maglaubig-offsite

Because the expression is so complex, I’d recommend breaking this into a few distinct steps. Something like this:

  1. Render Text and Store as Variable: render {{email.subject}} and store it as custom.subject
  2. Render Text and Store as Variable: only perform this action if custom.subject matches regular expression /T20[0-9]{6}.[0-9]{4}/. If it does, then render {{before_regex email.subject “/T20[0-9]{6}.[0-9]{4}/” flags=“t”}} and store it as custom.subject.

At this point, you could use {{custom.subject}} anywhere in your workflow, and it will contain either the entire subject line, or just the part before the ticket number.

Because you’ve broken the steps out, you can also better troubleshoot the steps by following along in the history logs. You can view each step to be sure it rendered what you expected.

Let us know how this works!

Sometimes you can’t see the forest through the trees. Thanks for the suggestion it worked great!

Splitting it out into 3 text render steps. The first was to populate the custom subject with whatever was in {{email.subject}}. The second was to format if the subject was blank, and the last to strip out an Autotask ticket number and then the create task used the {{custom.subject}} as the ticket title.

Awesome! Glad to hear it was helpful! :grinning: