File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ /********************************************************************************/
2
+ Input:
3
+ attachmentQuery - Pass sysId CSV attachment
4
+
5
+ Output:
6
+ converted into object from CSV
7
+
8
+ /********************************************************************************/
9
+
10
+ function parseCSVFile ( sysId ) {
11
+ var attachmentRecord = new GlideRecord ( "sys_attachment" ) ;
12
+ attachmentRecord . get ( sysId ) ;
13
+ attachmentRecord . query ( ) ;
14
+
15
+ if ( attachmentRecord . next ( ) ) {
16
+ var stringUtil = new GlideStringUtil ( ) ;
17
+ var sysAttachment = new GlideSysAttachment ( ) ;
18
+ var bytesData = sysAttachment . getBytes ( attachmentRecord ) ;
19
+ var encData = stringUtil . base64Encode ( bytesData ) ;
20
+ var decData = stringUtil . base64Decode ( encData ) + '' ;
21
+
22
+ var delimiter = ',' ;
23
+ var quoteCharacter = '"' ;
24
+ var csvArray = decData . split ( "\r\n" ) ;
25
+
26
+ var index = 0
27
+ var result = [ ] ;
28
+ for ( index = 0 ; index < csvArray . length ; index ++ ) {
29
+ var row = csvArray [ index ] ;
30
+ if ( row ) {
31
+ var csvParser = new sn_impex . CSVParser ( ) . parseLineToArray ( row , delimiter , quoteCharacter ) ;
32
+ var rowObject = { } ;
33
+ for ( var i = 0 ; i < csvParser . length ; i ++ ) {
34
+ rowObject [ 'column' + ( i + 1 ) ] = csvParser [ i ] ;
35
+ }
36
+ result . push ( rowObject ) ;
37
+ }
38
+ }
39
+ return result ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments