Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Excel workbook

William08
Tera Contributor

Hi all,

 

Need a help can we write the cell or edit the cell in excel using GlideExcelParser if not by this is there is  a way we can achieve this?

 

Thanks 

1 ACCEPTED SOLUTION

Hi @William08 

To read the file as below


  var csvFileCount=0;
  var ritmGr=//Gr can be of any table where csv is present;
  var RITMsys_id= ritmGr.getUniqueValue();
  var gsa = new GlideSysAttachment();
  var agr = gsa.getAttachments('sc_req_item', RITMsys_id);
    var gsa1 = new GlideSysAttachment();
    var agr1 = gsa1.getAttachments('sc_req_item', RITMsys_id);
    while(agr1.next())
    {
      var bytesInFile = gsa.getBytes(agr1); // tablename, table sysID
      var originalContentsInFile = Packages.java.lang.String(bytesInFile); // originalContentsInFile
      originalContentsInFile = String(originalContentsInFile);            
      var fileData = originalContentsInFile.split('\n');
      var csvHeaders = fileData[0] ;
      var csvHeadersValues = csvHeaders.split(','); //"," is the delimiter
      gs.info(fileData)
        gs.info(csvHeaders )
    }
 

Thanks and Regards,

Saurabh Gupta

View solution in original post

5 REPLIES 5

Saurabh Gupta
Kilo Patron

Hi,
Excel I am not sure but csv you can do.



Thanks and Regards,

Saurabh Gupta

Hi @Saurabh Gupta  

 

How do we edit the csv could please provide the script? 

Hi @William08 
To create the CSV file you can refer below script

var grX = new GlideRecord(targetTable);//Whatever your table
  grX.addQuery('sys_id',targetSys_id);//the record's sysid on which you want to add this 
  grX.query();
  if(grX.next())
  {
    var grAttachment = new GlideSysAttachment();
    grAttachment.write(grX, fileName, 'application/csv', csvData);
  }
//Name can be of your choice like fileName=DemoCSVFile
//the data can be like below
//csvData="Name;Address;ID\nSaurabh;India;Ge5363\nWilliam08;Out of India;Ge1234"

Thanks and Regards,

Saurabh Gupta

Hi @William08 

To read the file as below


  var csvFileCount=0;
  var ritmGr=//Gr can be of any table where csv is present;
  var RITMsys_id= ritmGr.getUniqueValue();
  var gsa = new GlideSysAttachment();
  var agr = gsa.getAttachments('sc_req_item', RITMsys_id);
    var gsa1 = new GlideSysAttachment();
    var agr1 = gsa1.getAttachments('sc_req_item', RITMsys_id);
    while(agr1.next())
    {
      var bytesInFile = gsa.getBytes(agr1); // tablename, table sysID
      var originalContentsInFile = Packages.java.lang.String(bytesInFile); // originalContentsInFile
      originalContentsInFile = String(originalContentsInFile);            
      var fileData = originalContentsInFile.split('\n');
      var csvHeaders = fileData[0] ;
      var csvHeadersValues = csvHeaders.split(','); //"," is the delimiter
      gs.info(fileData)
        gs.info(csvHeaders )
    }
 

Thanks and Regards,

Saurabh Gupta