Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Split the value of a string into two values separated by a period

ccepts
Mega Expert

Goal:

I want to split value in string field (u_text) into Short Description field (The value in u_text is usually two words i.e full name such as First Last). This means the value in the Short Description field should become First.Last. I am trying to get a period in between the first and last name

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){
var sd = inc.getValue('u_text').split(" ");
var ftext= sd.Split[0];
var stext=sd.Split[1];
current.short_description = ftext.stext; 
inc.update();

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Hi,

 

This is another flavor of achieving the same thing. 

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){
var sd = inc.getValue('u_text');
current.short_description = sd.replace(' ', '.'); 
inc.update();
}

 

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

View solution in original post

4 REPLIES 4

Chander Bhusha1
Tera Guru

Hi ccepts,

You can update your script to this one :

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){
var sd = inc.getValue('u_text').split(" ");
var ftext= sd[0];
var stext=sd[1];
current.short_description = ftext+'.'+stext+'.'; 
inc.update();

 

 

Thanks,

CB

MrMuhammad
Giga Sage

Hi,

 

This is another flavor of achieving the same thing. 

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){
var sd = inc.getValue('u_text');
current.short_description = sd.replace(' ', '.'); 
inc.update();
}

 

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

Hitoshi Ozawa
Giga Sage
Giga Sage

Following code will replace divide all words with a period. replace is a little bit faster than split/join so is preferred.

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){
  current.short_description = inc.getValue('u_text').replace(/ /g, "."); 
  inc.update();
}

 

 

Megha Padale
Giga Guru

Hi,

Check below script

var inc = new GlideRecord('Incident');
inc.addEncodedQuery('active=true^state=2^category=inquiry');
inc.query();
while(inc.next()){


var sd = inc.getValue('u_text');

current.short_description= sd.replace(/ /g, "."); 
inc.update();

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.