if incident record if their any attachment no need to show any alert .If attachment is not their show the alert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2017 10:03 AM
hi ,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 02:21 AM
Hi,
If my understanding is correct, you need to check whether the Incident Record has any attachments added or not. In order to do so we need to write an before Insert/Update business Rule on the Incident table as per the script mentioned below:
Script:
(function executeRule(current, previous /*null when async*/) {
var att = new GlideAggregate('sys_attachment');
att.addAggregate('COUNT');
att.addQuery('table_name', current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
var count = 0;
if (att.next()) {
count = att.getAggregate('COUNT');
if (count<1) {
gs.addInfoMessage("Please attach Attachment");
current.setAbortAction(true);
}
}
})(current, previous);
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2025 01:38 AM
Great it worked for me...but after I am saving the incident I am moving out of the incident page..how do I stay on the same form even after saving it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 02:22 AM
You can create a OnSubmit on incident table to Glide the record on sys_attachment table. if there is any record then don't show alert else show alert to attach a file.
- function onSubmit() {
- var sys_id = current.getUniqueValue();
- var gr = new GlideRecord("sys_attachment");
- gr.addQuery("table_name", gs.getTableName());
- gr.addQuery("table_sys_id", sys_id);
- gr.query();
- if (!gr.next()) {
- alert("You must attach a file to submit.");
- return false;
- }
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2017 02:30 AM
As recommended by Service Now Best practices, it's better not to Use Glide Record on a Client Side Script. for checking the count of attachments present or not on the form.
Glide Aggregate on the Server side would be the ideal choice to check for the Attachments added or not to the form for better System performance and to simply abort the Form submission if the Attachment has not been uploaded.
Regards,
Shloke
Regards,
Shloke