Remove trailing characters in a String field on table records

Vivin Viswanath
Tera Contributor

Hi folks, 

 

Looking to remove ".0" off of String fields that have accumulated over the years. 

 

Here's what I'm trying to execute. Alternatively, I tried using .slice as well. I can't shake the feeling it's something basic and I should probably stop working at 3am. 

var trailingZero = new GlideRecord("task");
trailingZero.addEncodedQuery('fieldLIKE.0');

while(trailingZero.next()) {
	var trailingGone = trailingZero.field.replace(/.0/,'');
	trailingZero.setValue('field,trailingGone);
	trailingZero.update();
}

 

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @Vivin Viswanath ,

I fixed your script in my PDI there are some error in that. Please refer below code 

 

var trailingZero = new GlideRecord("task");
trailingZero.addEncodedQuery('fieldLIKE.0');
trailingZero.query();
while(trailingZero.next()) {
	var field = trailingZero.getValue("field");
	var trailingGone = field.replace(".0",'');
	trailingZero.setValue('field',trailingGone);
	trailingZero.update();
}

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

View solution in original post

Vishal Khandve
Kilo Sage

Hi Vivin,

 

you can use the slice() method.

here is the code for your reference.

 

var trailingZero = new GlideRecord("task");
trailingZero.addEncodedQuery('fieldLIKE.0');
trailingZero.query();
while(trailingZero.next()) {
    var field = trailingZero.getValue("field");
    var trailingGone = field.slice(0,-2);
    trailingZero.setValue('field',trailingGone);
    trailingZero.update();
}

 

 

Thank you,

Vishal Khandve

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @Vivin Viswanath ,

I fixed your script in my PDI there are some error in that. Please refer below code 

 

var trailingZero = new GlideRecord("task");
trailingZero.addEncodedQuery('fieldLIKE.0');
trailingZero.query();
while(trailingZero.next()) {
	var field = trailingZero.getValue("field");
	var trailingGone = field.replace(".0",'');
	trailingZero.setValue('field',trailingGone);
	trailingZero.update();
}

 

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Thanks, Sartha! I'll give this a whirl. 

Both yours and Vishal's solutions worked. I marked them both as acceptable. 

Vishal Khandve
Kilo Sage

Hi Vivin,

 

you can use the slice() method.

here is the code for your reference.

 

var trailingZero = new GlideRecord("task");
trailingZero.addEncodedQuery('fieldLIKE.0');
trailingZero.query();
while(trailingZero.next()) {
    var field = trailingZero.getValue("field");
    var trailingGone = field.slice(0,-2);
    trailingZero.setValue('field',trailingGone);
    trailingZero.update();
}

 

 

Thank you,

Vishal Khandve