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

how to get a text from between of string

ST9
Tera Contributor

Hi All,

I wanted to extract a Order Number(123456789) and save that text to a particular custom field.

Example this- 

Order Number: 123456789
Candidate Name: Albert Test
Profile link: check

Hello

First Advantage is conducting a background check..

 

I have written a BR and getting a order number properly but the issue is if the order number is empty, the result is giving me a "Candida"

var des= current.description;
var index = des.indexOf("Order Number:");
var orderNum = des.substring(index+14, index+23);
	current.u_order_number= orderNum;

Please help

7 REPLIES 7

Prince Arora
Tera Sage

@ST9 

 

Though its difficult to trace it, but we can play a trick here as follows

 

var des= current.description;
var index1 = des.indexOf("Order Number:");

var index2 = des.indexOf("Candidate");
var orderNum = des.substring(index1+14, index2);
current.u_order_number= orderNum;

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

ST9
Tera Contributor

this worked but what if the candidate word is not there, then this will not work

Karan Chhabra6
Mega Sage

Hi @ST9 ,

 

If this is the only number in the content string, you can use this regex as well

var des= current.description;
current.u_order_number= des.replace(/[^0-9]/g,"");

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

Hi Karan,

when i tried this in Background script.

var gr= new GlideRecord('sn_hr_core_case');
gr.addQuery('sys_id','4976d51d97b66510857c9904a253af41');
gr.query();
if (gr.next()) {
var desc = gr.description;
var matches = desc.replace(/[^0-9]/g,"");
gs.info(matches);
}

it is giving me this o/p-

111111111111111110043094666428211304761

this was the description 

ST9_0-1684049615508.png