export to email

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 12:48 PM - edited 04-14-2023 12:50 PM
I have a requirement to disable this popup. Even if the export data exceeds a defined limit the system should not allow email export. Rather it should restrict the user from exporting it with a message that export limit has been exceeded
Please help me with this

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 01:24 PM
Hi Amrit,
To disable the popup that appears when a user tries to export data that exceeds a defined limit in ServiceNow, and instead restrict the user from exporting with a message that the export limit has been exceeded, you can create a Business Rule with the following script:
// Disable email export when the data limit is exceeded
// Define the data limit and the error message
var dataLimit = 5000; // Change this to your desired limit
var errorMessage = "Export limit exceeded. Please narrow your search criteria and try again.";
// Get the request type and the number of records to be exported
var requestType = current.sys_class_name;
var recordCount = 0;
if (requestType == "sys_report" || requestType == "sys_script_include") {
// For reports and script includes, get the number of rows from the preview
var rows = parseInt(g_request.getParameter("sysparm_preview_row_count"));
if (rows > 0) {
recordCount = rows;
}
} else {
// For other tables, get the number of records in the result set
recordCount = current.getRowCount();
}
// Check if the data limit is exceeded
if (recordCount > dataLimit) {
// Set the error message and prevent the export
current.setAbortAction(true);
current.setReturn("Export limit exceeded. " + recordCount + " records selected. Limit is " + dataLimit + " records.");
}
This script will run before the export action is executed, check if the number of records to be exported exceeds the defined limit, and if it does, it will set an error message and prevent the export. The user will see the error message and will not be able to export the data until they narrow their search criteria to stay within the export limit.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 12:34 AM - edited 04-18-2023 12:35 AM
Thanks for this reply but it doesn't work for me. Could you kindly give a little bit for more details on what type of BR i have to push in?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 04:32 AM
Hi Amrit,
To implement this code, follow these steps:
- Navigate to the "Business Rules" module in ServiceNow.
- Click "New" to create a new business rule.
- Enter a name for the business rule, such as "Export Limit Business Rule".
- Set the "Table" field to the table where the export action is located.
- In the "Advanced" section, check the "Before" checkbox and set the "When" field to "update".
- In the "Script" field, copy and paste the code you provided.
- Modify the "dataLimit" variable to your desired limit.
- Modify the "errorMessage" variable to your desired message.
- Save the business rule.
Thanks,
Rahul Kumar
Thanks,
Rahul Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2023 04:53 AM
didn't work.