- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 02:42 AM
Hi,
I am currently using a script that stores all duplicate CI serial number in an array. Now my requirement is to export the data stored in the array to an excel file.
Is there any way I can dump the data from the script to an excel file.
Regards,
Debjit
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 03:20 AM
Hi,
Below is sample code
var grX = new GlideRecord("sys_user");//some where we need to save the file here I am attaching on one of the user record logged in one
var csvData="";//This should always be in the 2D array format
//FieldLabel1,FieldLabel2,FieldLabel3,FieldLabel4=====This Row is For Header of CSV
//Val11,Val12,Val13,Val14==== Row 1
//Val21,Val22,Val23,Val24 ==== Row 2
grX.addQuery('sys_id',gs.getUserID());
grX.query();
if(grX.next())
{
csvHeader="UserID,Name,Company\n";
csvRows1="ABC1,Mario1,SPM1\n";
csvRows2="ABC2,Mario2,SPM2\n";
csvRows3="ABC3,Mario3,SPM3\n";
csvData=csvHeader+csvRows1+csvRows2+csvRows3;
var grAttachment = new GlideSysAttachment();
grAttachment.write(grX, "User Details.csv", 'application/csv', csvData);
}
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 02:44 AM
Hi,
Excel I am not sure in csv you can do.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 03:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 03:20 AM
Hi,
Below is sample code
var grX = new GlideRecord("sys_user");//some where we need to save the file here I am attaching on one of the user record logged in one
var csvData="";//This should always be in the 2D array format
//FieldLabel1,FieldLabel2,FieldLabel3,FieldLabel4=====This Row is For Header of CSV
//Val11,Val12,Val13,Val14==== Row 1
//Val21,Val22,Val23,Val24 ==== Row 2
grX.addQuery('sys_id',gs.getUserID());
grX.query();
if(grX.next())
{
csvHeader="UserID,Name,Company\n";
csvRows1="ABC1,Mario1,SPM1\n";
csvRows2="ABC2,Mario2,SPM2\n";
csvRows3="ABC3,Mario3,SPM3\n";
csvData=csvHeader+csvRows1+csvRows2+csvRows3;
var grAttachment = new GlideSysAttachment();
grAttachment.write(grX, "User Details.csv", 'application/csv', csvData);
}
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2023 04:21 AM
Hi @Saurabh Gupta ,
Thank you for the response.
Allthough the requirement is not exactly the same, but I think I will be able to work with the code you have shared and make adjustment to make it work.
Regards,
Debjit