0

Fetching Contents from CSV File Attached to your record:

  • getBytes() : This returns the raw bytes of the file — that means binary data.
  • java.lang.String() : we convert that data into a string using.

var   attac= new GlideRecord('sys_attachment');

attac.addQuery('sys_id', 'record_sys_id'); // sys_id of attachment record

attac.query();

if(attac.next()){

var gsa = new GlideSysAttachment();

var bytesFile = gsa.getBytes('incident', 'incident_sys_id');

var originalContentsInFile = Packages.java.lang.String(bytesFile);

originalContentsInFile = String(originalContentsInFile);

gs.print("Contents of Attached CSV File:  "+originalContentsInFile);

}

Fetching Contents from CSV File using getBytes() Function ServiceNow
Working Code Asked question July 4, 2023