File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Fix scripts/Remove leading and trailing spaces Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## Fix script to remove leading and trailing spaces from a field in bulk
2
+
3
+ - we often encounter in a situation that a field has leading or trailing spaces and we want to remove it
4
+ - This fix script helps to remove leading and trailing spaces from a field in bulk number.
5
+ - Just for an example I have taken incident table and short description as a field.
6
+ - feel free to modify and use it as per your requirement.
7
+
Original file line number Diff line number Diff line change
1
+ var page = 1 ;
2
+ var count = 0 ;
3
+ var infoMsg = 'Fix Script to remove leading or trailing spaces from short_description. \n' ;
4
+ var sd = '' ; //sd inshort for shortdescription
5
+
6
+
7
+ var regExSpacecheck = / ^ \s + | \s + $ / g; //regular expression to check if a sentence has leading and trailing spaces.
8
+
9
+ var grInc = new GlideRecord ( 'incident' ) ;
10
+ grInc . addEncodedQuery ( 'short_descriptionISNOTEMPTY' ) ;
11
+ grInc . query ( ) ;
12
+ while ( grInc . next ( ) ) {
13
+
14
+ if ( regExSpacecheck . test ( grInc . short_description ) ) {
15
+
16
+ infoMsg += 'incident record found with leading or trailing space for short_description: ' + grInc . sys_id + '\n' ;
17
+ infoMsg += 'Sd ' + grInc . short_description + 'Contains leading or trailing spaces \n' ;
18
+ sd = grInc . short_description ;
19
+ sd = sd . trim ( ) ; //trimmed value of short description
20
+ infoMsg += 'sd is ' + sd + '\n' ;
21
+
22
+ if ( regExSpacecheck . test ( sd ) ) {
23
+ infoMsg += 'sd: ' + sd + ' still has a trailing space\n' ;
24
+ } else {
25
+ infoMsg += 'sd: ' + sd + ' no longer contains trailing space \n' ;
26
+ }
27
+ //Replace the value for u_location_svid with the trimmed version
28
+ grInc . setValue ( 'short_description' , sd ) ;
29
+ grInc . setWorkflow ( false ) ;
30
+ grInc . update ( ) ;
31
+
32
+ count ++ ;
33
+
34
+ if ( count == 50 ) {
35
+ gs . info ( infoMsg ) ;
36
+ page ++ ;
37
+ count = 0 ;
38
+ infoMsg = 'Fix Script to remove leading or trailing spaces from short_description (' + page + ')\n' ;
39
+ }
40
+
41
+ }
42
+
43
+ }
You can’t perform that action at this time.
0 commit comments