Download the data to the EXCEL or CSV file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:41 PM - edited 03-25-2024 09:47 PM
I need to download the data which is stored in an array to Excel or CSV file through script. Can you please help me with the requirement.
I have some custom 10 records data stored in array. When we click on button or link, So I need to download those records into excel or csv file through script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:44 PM
Hi @Aman44
Could you please explain your requirement clearly. These lines doesnt helps to understand your query.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:49 PM - edited 03-25-2024 09:51 PM
Hi Deepak,
I am trying to capture the ignored records while transform map and storing them in array. I am able to show the ignore records in the info message. but now I need to get those ignored records data into excel or csv file when we click on link or button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 09:59 PM
Hi @Aman44
If you are setting up a process to capture and subsequently export ignored records, you’ll need to employ scripting, utilize ServiceNow’s capabilities for data export, and perhaps create a custom UI action if you want a button or link directly on a form.
Step 1: Capture Ignored Records During Transformation
During the data transformation process, you can use a script in the Transform Map to detect and capture records that are being ignored. For example, you might use an onBefore script to check conditions and then store records that will be ignored in a custom table designed for this purpose.
// Example condition to determine if a record will be ignored
if (source.u_some_field == '') {
// Logic to capture the record
var gr = new GlideRecord('u_ignored_records'); // Assuming ‘u_ignored_records’ is your custom table for capturing ignored records
gr.initialize();
gr.u_source_record = source.sys_id.toString(); // Capture the sys_id or other identifying info from the source record
// Add more fields as needed
gr.insert();
}
Step 2: Create a List or Report of Ignored Records
Once you have your ignored records being captured to a custom table, you can create a list view or report in ServiceNow that shows these records. This view can then be used as the basis for exporting the data.
Step 3: Implement a UI Action for Export
To create a button or link that allows users to export the ignored records, you can implement a UI Action. This UI Action can be configured to appear on the list view or form where your ignored records are displayed.
1. Navigate to System Definition > UI Actions.
2. Click New to create a new UI Action.
3. In the form, you might fill out:
- Name: Export to CSV (or as desired)
- Table: u_ignored_records (or your custom table)
- Action name: export_to_csv (or as needed; this is used in script)
- Client: True (since the action involves client-side script)
- Form button: True (if you want it to appear as a button)
- List choice: True (if it should appear in list views)
var url = '/export_to_csv.do?sysparm_query=YOUR_QUERY_HERE&sysparm_target=u_ignored_records';
window.open(url, '_blank');
Replace YOUR_QUERY_HERE with the specific query parameters needed to filter the records in your custom table (if any filtering is applied).
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 10:13 PM