Hello Everyone I want to remove white spaces from short discription by using background script

Aditya37
Tera Contributor

Want to remove first white space of short discription 
suppose i give short discription --->  test then i want to remove the white space before the test
Also want to remove all incident short discription white spaces.

Could you please help me about this.

find_real_file.png

 

Thanks.

1 ACCEPTED SOLUTION

Hi,

for new records you can use before insert/update BR and use trim() method

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.short_description = current.short_description.trim();

})(current, previous);

for existing records you can run fix script and run it once.

updateRecords();

function updateRecords(){
	try{
		var gr = new GlideRecord("incident");
		gr.query();
		while (gr.next()) {
			gr.short_description = gr.short_description.trim();
			gr.update();
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use trim() method and it will remove any leading or trailing spaces

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

for new records you can use before insert/update BR and use trim() method

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	current.short_description = current.short_description.trim();

})(current, previous);

for existing records you can run fix script and run it once.

updateRecords();

function updateRecords(){
	try{
		var gr = new GlideRecord("incident");
		gr.query();
		while (gr.next()) {
			gr.short_description = gr.short_description.trim();
			gr.update();
		}
	}
	catch(ex){
		gs.info(ex);
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Aditya37
Tera Contributor

Thank you for your response. Its working as expected.

Regards
Aditya