Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to remove empty space from phone number using script.

Sriharsha3
Tera Contributor

How to achieve this using a transform script before loading of data or a business rule after load/.

Suppose my phone number looks this way from data : +91 9xxxxxxxxx , i need it to transform to +919xxxxxxxxx so there is no inbetween spaces.

 

Thanks

1 ACCEPTED SOLUTION

You can write this in your before script

var number = source.u_number; //Replace u_number with the actual import set column name for phone number

number= number.replace(" ", "");
target.mobile_phone = number;

 

View solution in original post

10 REPLIES 10

write before transform script

and code like

 var res=source.u_mobile_phone;

mob_phone=res.replace(" ","");

and then initialize it to target like

targate.mobile_no=mob_phone;

 

OR

Open your field map mob_no

there u ll get run script option 

and write above script in script field.

 //use proper syntax

 

Thanks

 

 

 

 

Varsha21
Giga Guru

Hi,

use fieldname.trim(); it will remove spaces between it.

 

Thanks

Dubz
Mega Sage

something like this should work:

var str = '+91 9xxxxxxxxx';
var str2 = str.replace(' ', '');
return str2;

Community Alums
Not applicable

Hi Param,

User below script to remove all space from phone number:

var number = '+91 9x xx xx xxxx';
number = number.replace(/ /g, '');
return number;

 

Thanks,

Harish

Rahul Kumar17
Tera Guru

hi

var number = '(123) 456-7891';
number = number.replace(/[^\d]/g, '');
gs.print(number);

or

var number = '+91 966 8890 789';
number = number.replace(/ /g, '');
gs.printnumber;

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar