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 the whitespace business rule

Mrman
Tera Guru

Hi ,

I have created a business rule to replace a line in the Description field with empty space . 

It is working and that line is replaced with blank space . Now I want to remove this white space and move Up the line below it .

Please guide how to achieve it .

find_real_file.png

1 ACCEPTED SOLUTION

@ramamr 

I just used the same script and it worked fine for me

Original Message

find_real_file.png

Script:

var gr = new GlideRecord('problem');
gr.get('a463aa81db41e010224a2a9a48961954');

var desc = gr.description;
gs.info('Original String->\n' + desc);

desc = desc.replace(/Legal Entity Code: LE-[A-Z]+[\d]{3}/g, '');

var arr = desc.replace(/(\r\n|\n|\r)/gm, "@").replaceAll('@',',').split(',');
var finalArr = [];
for(var i in arr){
if(arr[i] != ''){
finalArr.push(arr[i].toString());
}
}

var finalString = finalArr.join('\n');

gs.info('Final String->\n' + finalString);

gr.description = finalString;
gr.update();

find_real_file.png

find_real_file.png

Regards
Ankur

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

View solution in original post

19 REPLIES 19

@ramamr 

You can use before insert BR

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

	// Add your code here
	var arr = [];
	var variables = current.variables.getElements(); 
	for (var i=0;i<variables.length;i++) { 
		var question = variables[i].getQuestion();
		var label = question.getLabel();
		var value = question.getDisplayValue();
		if(label != '' && label != 'Legal Entity Code'){
			var str = label + ":" + value + "\n"; 
			arr.push(str + "");
		}
	}
	current.description = arr.join('\n');	

})(current, previous);

Regars
Ankur

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

Thanks @Ankur Bawiskar there is an OOB script includes which get called from the HR record producers OOB . 

Instead of customizing that OOB script , taken this approach of removing that variable question . 

I am able to accomplish what is required for now with the help of script you provided . 

 

Glad to help.

Please remember to mark appropriate response helpful as well.

Regards
Ankur

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

harun_isakovic
Mega Guru

You want to move the blank space under that 2nd line or move the entire text up by 1 line, if so then just remove that line break command from your business rule. Either way share the business rule code please.

Hi ,

In the screenshot provided ,  under "The following fields have been provided:" there is White space and now I want to move the line below white space up . I shared the BR in my previous update.