Parse the CSV attachment.

PK16
Tera Expert

Hello Community Experts,

I want to parse the CSV attachment and get the data present in that in the flow designer.

Is there any resources or script you have so that I can use them for reference?

(Note: I want to fetch the attachment from the sys_attachment table and parse it and display the values in the background script. After that, I will customize that in flow designer as well).

 

Regards,

PK

9 REPLIES 9

Hi,

you should pass the header information as well

like this and then use parseLineToArray method and pass the header

var headers = ['Name','Email'];

Regards
Ankur

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

Hi @Ankur Bawiskar ,

Please let me know if I'm doing something wrong in the below code :-  

try {
var attachment = new GlideSysAttachment();
var headers = ['title', 'description', 'owner','order'];
var delimiter = ',';
var attachmentStream = attachment.getContentStream('1722a8da2fe5d1101a5cf3ecf699b65b');
var x = new sn_impex.CSVParser().parseLineToArray(attachmentStream,headers,delimiter);

gs.log('From CSV:'+x[0]);


}
catch(ex) {
      gs.info("In Catch:"+ex.message);
}    

 

Output:-

find_real_file.png

Thanks

Hi,

you use this to parse

try {

	var attachment = new GlideSysAttachment();

	var attachmentStream = attachment.getContentStream('1722a8da2fe5d1101a5cf3ecf699b65b');

	// now parse each line
	

}
catch(ex) {
	gs.info("In Catch:"+ex.message);
}

Regards
Ankur

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

SaiDeepakk
Tera Contributor

Is there any solution to this question and if yes can someone please provide all the scenarios and steps to replicate this.

Tejaswini Cheb1
Tera Contributor

Hi All, 
Any solution for above question, even I'm trying to achieve similar thing.