- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:17 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:53 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:38 AM
Hi,
Excel I am not sure but csv you can do.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 10:53 AM
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