The CreatorCon Call for Content is officially open! Get started here.

JavaScript String search() Method

SW7
Giga Guru

Hi Community,

Hope you are all keeping well. I have a particular use case for scripting in flow designer whereby I want to scrape the body of an email and search for the text that contains the Ticket Description: [Ticket: Description] in the body as below and then returns the text after the Ticket Description within the same line. 

The above will be used in my flow to map (fx) to the description within the ticket flow,

Can someone please provide guidance on the search string which should be used to identify the ticket Description text and the return the string after.

Many thanks

Steve  

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

Here is how you can do a check

//str should be your email body.
var str = fd_data.trigger.current.body_text.toString();
if (str.indexOf("Ticket Description:") > -1) {
   var body = str.split("Ticket Description:");
   body = body[1].toString();
   body = body.split("\r\n");
   var ticket_desc = body[0].toString(); // This will store your ticket description
}

Mark the comment as a correct answer and also helpful if this solves the problem.

 

View solution in original post

9 REPLIES 9

asifnoor
Kilo Patron

Hi,

Here is how you can do a check

//str should be your email body.
var str = fd_data.trigger.current.body_text.toString();
if (str.indexOf("Ticket Description:") > -1) {
   var body = str.split("Ticket Description:");
   body = body[1].toString();
   body = body.split("\r\n");
   var ticket_desc = body[0].toString(); // This will store your ticket description
}

Mark the comment as a correct answer and also helpful if this solves the problem.

 

Asifnoor,

Thank you for the guidance, much appreciated. 

Many thanks

Steve

Asifnoor,

I just tested out the solution, which unfortunately didn't work, so I tested out this script which copies the body of the email into the description field, however now I need to just copy the information that will exist on one line after the Ticket Description: 

This is what I used which did copy the body to the description field:

var shortDesc1 = '';
var shortDesc2 = '';
shortDesc1 = fd_data.trigger.inbound_email.body_text
shortDesc2 = shortDesc1.replace('Ticket Description', '');
return shortDesc2;

Are you able to advise the correct code to copy the line of text after the Ticket Description, but not anything below it and return the output to the description field, which works as above?

 

Many thanks

Steve

 

Asifnoor,

Ignore that last message, needed to make some changes to the script and managed to get this working like you mentioned,

Thanks again

Steve

Okay, cool.