- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 08:23 AM
Hello
I'm still new to service now. I would like to replace blanks on attachment.
I have created a business rule for insert into sys_attachment.
###############################################################################
(function executeRule(current, previous /*null when async*/) {
    var v_file_name = current.file_name; 
    
    v_file_name.replace(/\s+/g, '_');
    current.file_name = v_file_name + 'xxxx';
})(current, previous);
###############################################################################
Result: The filename is extended by "xxxx" (was just for debugging) but the blanks are still there.
############################ Script Background ###################################
var v_file_name = 'file name with blanks'; 
gs.log(v_file_name.replace(/\s+/g, '_'));
###############################################################################
Here I get the expected result.
Sincerely Detlef
Solved! Go to Solution.
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 12:07 PM
Hi,
Try this code.
(function executeRule(current, previous /*null when async*/) {
    var v_file_name = current.file_name;
    v_file_name = v_file_name.replaceAll(" ","_");
    current.file_name = v_file_name + 'xxxx';
})(current, previous);Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 08:29 AM
Hi,
Try this: v_file_name.replace(/\s/g, '');
If it was helpful, please give positive feedback.
Thanks,
☆ Community Rising Star 22, 23 & 24 ☆
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2020 12:07 PM
Hi,
Try this code.
(function executeRule(current, previous /*null when async*/) {
    var v_file_name = current.file_name;
    v_file_name = v_file_name.replaceAll(" ","_");
    current.file_name = v_file_name + 'xxxx';
})(current, previous);Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2020 12:16 AM
Hello
I found the solution: escape the escape character !
(function executeRule(current, previous /*null when async*/) {
    var v_file_name = current.file_name; 
    
    var v_r = new SNC.Regex('/\\\s+/');
    var v_replaced = v_r.replaceAll(v_file_name, '_');
    current.file_name = v_replaced;
})(current, previous);
