attachment check on UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 06:00 AM
Hi,
How can we make attachment mandatory if not attached to form on clicking UI action. Basically Before any action after clicking button, it has to check attachment and a field value should be filled, if not i has to alert user and stop UI action functionality going further. Kindly help with this scenario.
Thanks,
Lean S

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 06:17 AM
Hi Lean,
Please refer below link and adjust it as per your req.
Mandatory Attachment Before State Change

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 06:47 AM
Hello Lean,
You can also write before insert and update business rule to check mandatory attachment.
For reference check following script.
Before insert BR :
var attachRec = new GlideRecord("sys_attachment");
attachRec.addQuery("table_name", current.getTableName());
attachRec.addQuery("table_sys_id", current.sys_id);
attachRec.query();
if (!attachRec.next()) {
gs.addErrorMessage("You must attach a file before submitting.");
current.setAbortAction(true);
}
Regards,
Harshal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 08:14 AM
Hi Harshal,
Thanks for the response on this. If I want to make UI action script stop triggering before any attachment is attached. Is that BR will stop that UI action running, in my testing now I saw UI action is running backend. Kindly suggest
Thanks,
Lean S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 08:28 AM
what I could get from question is that you want attachment to be checked before UI action code runs
So the above code would stop the UI action code from running.
You can handle it in other way. Show UI action only when there is some attachment to the current record
In the UI action condition add this
current.hasAttachments()
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader