About drag and drop of attachments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:11 AM
I want a popup to appear when I drag and drop an attachment onto a record.
I can operate the attachment screen on the UI page, but which record should I customize when attaching by drag and drop?
When attaching a file by drag and drop, I want to display a popup saying "Caution: Do not attach files with the same file name."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 07:51 AM - edited 09-25-2024 08:16 AM
You can achieve that by defining a business rule on the 'sys_attachment' table that runs on Insert and Before. with script logic:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var fileName = current.file_name;
var attachmentTable = new GlideRecord('sys_attachment');
attachmentTable.addQuery('file_name', fileName);
attachmentTable.query();
gs.info("Found " + attachmentTable.getRowCount() + " attachment records with " + fileName);
if (attachmentTable.next()) {
gs.info("Duplicate file name");
gs.addErrorMessage("Do not add duplicate file: " + fileName + "!");
current.setAbortAction(true);
}
})(current, previous);
The user must refresh the incident form though to see the attachment is missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 06:03 AM
Is it possible to display a popup?
I understand that this can be handled using business rules.
If possible, I would like to display a popup so that the file is saved when OK is pressed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 09:27 AM
I'm not sure how that would be done in a business rule. I don't know how to alter that aspect of OOB behavior.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 11:00 AM
Steps to Create a Popup for Drag-and-Drop Attachments in ServiceNow
Identify Target Table: Determine which table (e.g., Incident) you want to customize for attachments.
Create Client Script:
- Navigate to System Definition > Client Scripts.
- Click New and fill in:
- Name: Enter a descriptive name.
- Table: Select the target table.
- Type: Set to onLoad.
Add Script: Insert the provided JavaScript code to check for duplicate filenames and display a popup.
Test the Functionality:
- Open a record in the target table.
- Drag and drop a file to see if the popup appears for duplicates.
Submit: Save your Client Script and verify its functionality.
This will enable a popup warning for duplicate filenames during drag-and-drop uploads. Let me know if you need anything else!
If you find this helpful, please mark it as helpful!