Solved

Expression Builder: Extract mail from ticket description_text

  • 2 August 2022
  • 7 replies
  • 801 views

Userlevel 3
Badge +6

Hi 

I need some help with the following issue.

I try to extract an user e-mail address from a ticket description so I can use that data to update the ticket requestor in FS. 

In my workflow I have an API call defined to retrieve the ticket information, then use the JSON parses to define the outputs and using below output in my expression builder.

 "description_text": "Tue Aug 02 10:10:39 2022: Request 224889 was acted upon.\r\n\r\n Transaction: Status changed from 'open' to 'resolved' by aaaaa\r\n Actor Email: aaaaa@bbb.net\r\n       Queue: cccc\r\n     Subject: [#INC-100853] Test 5 - July 21\r\n       Owner: Nobody\r\n  Requestors: helpdesk@xxx.freshservice.com\r\n      Status: resolved\r\n    Priority: 0\r\n Ticket <URL: https://tickets.bbb.net/Ticket/D9 >\r\n\r\n\r\nThis transaction appears to have no content\r\n",

 

I try to extract the mail address that comes after Requestors: and before Status: running below expression

substring('{{ticket.description_text | sanitize_html}}',indexOf('{{ticket.description_text | sanitize_html}}', 'Requestors:',0)+length('Requestors:'), indexOf('{{ticket.description_text | sanitize_html}}', Status', indexOf('{{ticket.description_text | sanitize_html}}', 'Requestors:',0)) )

 

The result is “helpdesk@xxx.freshservice.com\\r\\n” 

I’m stuck with the  “\r\n” and have no clue how to remove this for the result using the expression builder? 
Does anyone has an idea how to do this?

icon

Best answer by vishal.abraham 2 August 2022, 13:56

View original

7 replies

Userlevel 3
Badge +3

Hey Richard, 

Can you give the expression below a go and see if it works?

 

substring('{{ticket.description_text | sanitize_html}}', indexOf('{{ticket.description_text | sanitize_html}}', 'Requestors:',0)+length('Requestors:'), indexOf('{{ticket.description_text | sanitize_html}}', '\',     indexOf('{{ticket.description_text | sanitize_html}}', 'Requestors:',0)) )

Userlevel 3
Badge +3

Alternatively, you can try passing the output of this expression as an input to another expression and use the expression below:

 

replace('{{E1.result}}', '\\r\\n','')

 

 

Userlevel 3
Badge +6

@vishal.abraham. I really thought I had already tried that but it works. Thank you. 

On your 2nd option. I had it as workaround. Only you need to exclude the “\” twice :) 

 

regexReplace('{{E3.result}}','\\\\n\\\\r','')

Userlevel 3
Badge +3

Great, glad it worked!

Badge +1

[post removed]

Userlevel 1
Badge +1

I was really happy to find this thread as I am running into the same issue myself, however, I tried the solution here and it doesn’t seem to be working for me. Here is my expression:

substring('{{ticket.description_text | sanitize_html}}',(indexOf('{{ticket.description_text | sanitize_html}}','Preferred Name (if applicable): ', 0)+32),(indexOf('{{ticket.description_text | sanitize_html}}','Last Name',0)))

I tried replacing ‘Last Name’ with ‘\’ as the solution here used, but when I do I just get an error “Invalid Syntax - Missing ).”. Otherwise, I still get the output with ‘\r\n’ at the end.

If anyone happens to see this and can help me out, I’d greatly appreciate it!

Userlevel 1
Badge +1

And of course 10 minutes later I’m able to answer my own question. If anyone else happens to come across this same issue, I had to use ‘\r’ to get it to function properly without the error. Here is my final expression that worked:

substring('{{ticket.description_text | sanitize_html}}',(indexOf('{{ticket.description_text | sanitize_html}}','Preferred Name (if applicable): ', 0)+32),(indexOf('{{ticket.description_text | sanitize_html}}','\r',(indexOf('{{ticket.description_text | sanitize_html}}','Preferred Name (if applicable): ', 0)))))

Reply