
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 05:11 AM
Hi All,
I trying to implement a UI action which allows us to export Requested Item number, item name, description and its variables (questions and values) in CSV file.
How to achieve this?
OOB export only export requested item(current record) but not its variables.
Thanks
Sandeep Bharate
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 05:21 AM
Hi Sandeep,
please try to create your UI Action using the below script (change <field1>, <field2>, <field3> with your own fields name):
var output = "Number,Company,Short_Description"; //header for csv file
var table = "sc_catalog";
var recordId = ""; //using for attachment file
var gr = new GlideRecord(table);
var count = 0;
while (gr.next()) {
count++;
output += "\n" + gr.<field1> + "," + gr.<field2>.getDisplayValue() + "," + gr.<field3>;
if (!recordId) {
recordId = gr.sys_id;
}
}
gs.print(recordId);
writeAttachmentFile(output);
function writeAttachmentFile(data) {
var attachment = new Attachment();
var attachmentRec = attachment.write(table, recordId, "export.csv", "text/csv", data);
}
When the UI Action will run, you can navigate to sys_attachment.list to download export.csv file.
Hope this will be useful for you.
Please, mark Correct or hit Helpful if you find my response worthy.
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 05:16 AM
Hi Sandeep,
you can create report for this and export that.
use report directly on sc_req_item table
https://docs.servicenow.com/bundle/london-performance-analytics-and-reporting/page/use/reporting/task/use-service-catalog-variables-in-report.html
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2018 05:21 AM
Hi Sandeep,
please try to create your UI Action using the below script (change <field1>, <field2>, <field3> with your own fields name):
var output = "Number,Company,Short_Description"; //header for csv file
var table = "sc_catalog";
var recordId = ""; //using for attachment file
var gr = new GlideRecord(table);
var count = 0;
while (gr.next()) {
count++;
output += "\n" + gr.<field1> + "," + gr.<field2>.getDisplayValue() + "," + gr.<field3>;
if (!recordId) {
recordId = gr.sys_id;
}
}
gs.print(recordId);
writeAttachmentFile(output);
function writeAttachmentFile(data) {
var attachment = new Attachment();
var attachmentRec = attachment.write(table, recordId, "export.csv", "text/csv", data);
}
When the UI Action will run, you can navigate to sys_attachment.list to download export.csv file.
Hope this will be useful for you.
Please, mark Correct or hit Helpful if you find my response worthy.
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2018 03:03 AM
Hi Sandeep,
Any update on this?
Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread.
Thanks in advance.
Cheers
Alberto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2020 11:03 PM
hi,
I want to download the file right away instead of attaching it to a record, is it possible?
can you please provide the code to be used in UI actions.
thanks