How to split a string and extract substring?

Sid_Takali
Kilo Patron
Kilo Patron

Hi all,

I have a requirement where I have to split a string  "Call Inbound from 01037669762  - ConnectionId: e7541016-1a5a-4c24-9375-0a3f8793e6cc"  and I have to extract a phone number(substring) "01037669762" and populate on consumer phone field.

find_real_file.png

9 REPLIES 9

Aman Kumar S
Kilo Patron

Use below code:

var str = "Call Inbound from 01037669762  - ConnectionId: e7541016-1a5a-4c24-9375-0a3f8793e6cc";
var strNum = str.split(' ');
gs.info(strNum[3]);
Best Regards
Aman Kumar

@Siddharam Takali 

 

Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

Hi @Siddharam Takali 

Is your issue resolved?


Feel free to mark correct, if your issue has been resolved, so it ends up in solved queue.

Will be helpful for others looking for the similar query.

Best Regards
Aman Kumar

Sagar Pagar
Tera Patron

Hi,

You have to get the short description value into string and the split it by space and get the contact no srting1[3].

Sample scripts-

Object will be GlideRecord/ current


var str = object.getValue("short_description").toString();  // Call Inbound from 01037669762  - ConnectionId: e7541016-1a5a-4c24-9375-0a3f8793e6cc

var string1 = str.split(" ");
gs.info(string1[3]);

 

Thanks,

Sagar Pagar

The world works with ServiceNow