How to split a string and extract substring?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 01:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:08 AM
Hi Sagar,
One correcttion here, when you use getValue() , that already returns string equivalent of the value, you don't need to convert it string explicitly
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:16 AM
Thanks
ok. understood.
if we get the values like
object.short_description.toString();
then, we have to use toString() method.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2022 07:20 PM
Hi
Good day!
Thanks for marking helpful! If my answer help you. Feel free to mark correct!
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:20 AM
Actually that is not correct in all cases: if object
is a GlideRecord and the field has no value. Then the returned value is null
, not a string. Of course, in that case even toString()
is not a solution, as stringifying a null
will not yield an empty string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 02:14 AM
Here's a variant that uses RegExp, looking for the word from followed by a number:
var regexp = /from\s(\d+)\s/;
var findings = regexp.exec('' + gr.short_description);
if (findings)
gr.consumer_phone = findings[1];
This assumes the script will be executed server side and gr
is the interaction GlideRecord. On client side it would be mostly the same, just that gr
has to be substituted using g_form
calls:
var regexp = /from\s(\d+)\s/;
var findings = regexp.exec(g_form.getValue('short_description'));
if (findings)
g_form.setValue('consumer_phone', findings[1]);