- 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
11-14-2024 10:30 AM
Hi , I was able to acheive this by bringing to Excel (.xlsx) instead of csv.
Just below copy paste the code, and u will have excel created in the specified record.
Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 09:45 AM - edited 11-22-2024 09:46 AM
Trying out your solution, I got the following error when opening the attachment: "The file extension and format of ... does not match". How were you able to fix that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2024 09:51 PM
Share your code here , will check and let know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 04:41 AM
Were you able to figure out how to fix this error?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2023 06:25 PM
I have a similar use-case. I'm learning ServiceNow from the developer perspective (Studio, client/server scripts, etc.), but still have a long way to go.
Is the script above a server-script (JavaScript)? Is it something that "power users" could do, or does it require lots of sensitive roles/permissions, where a large organization would be reluctant to grant access?
I'm currently learning on ServiceNow's "learn" site: my access at work is very limited at present.