- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 09:48 PM
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();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 10:36 PM
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
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 09:53 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 10:36 PM
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
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 10:47 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2020 11:18 PM
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.