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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to do string manipulation and then retrieve the data

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

Thank you for your response, do you have an example? I have a few different fields that I need to populate with this method, hence a good starting point would be an example.

 

Many thanks

Steve

Hi,

I assume you are using inbound email flow in flow designer

refer below links for help

Flow Designer - pull text from email body and act upon value

Has anyone managed to get Inbound Email Flow Designer working?

URGENT - inbound email flows are not working. Getting "Exception occurred while evaluating flow trig...

Also flow designer inbound email flow doesn't have that much capability as compared to inbound email action. So I would suggest if the flow approach doesn't work then please use inbound email action.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

We extensively use flow designer for many solutions, so won't be switching to email inbound actions. I have some scripts that do funky stuff already with regards to subject lines, however in this case I want to scrape the body.

The flow designer has everything we need to pull this information in and with the (fx) coding will be fine, just having trouble finding the correct code to scrape the description.

I hope that helps to explain

Thanks

Steve