how to get a text from between of string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 01:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 02:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2023 12:34 AM
this worked but what if the candidate word is not there, then this will not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2023 04:01 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2023 12:28 AM - edited 05-14-2023 12:33 AM
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