make attachment mandatory
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 02:37 AM
Write code to make attachment mandatory if priority is critical and state changed to resolved in Incident table.
Please suggest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 07:14 AM
Hi @snowsid88
Did you try using a UI Policy? It's low-code and easy to implement
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 07:24 AM
Hi @snowsid88 ,
you can create a before update BR on the incident table
with script
(function executeRule(current, previous /*null when async*/ ) {
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', current.getTableName());
attachmentGR.addQuery('table_sys_id', current.getValue('sys_id'));
attachmentGR.query();
if (!attachmentGR.hasNext()) {
gs.addErrorMessage('Attachments are required when resolving a Critical incident.');
current.setAbortAction(true);
}
})(current, previous);
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 11:35 AM
You can create a business rule and add the below script.
(function executeRule(current, previous /*null when async*/ ) {
if (current.hasAttachments() != true) {
gs.addErrorMessage("PLease add an attachment");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 12:00 PM - edited 08-01-2025 12:01 PM
Hi @snowsid88
As suggested above, you can create a Before Update BR with the required conditions
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if(current.hasAttachments != true){
gs.addErrorMessage("Attachment is mandatory.");
current.setAbortAction(true);
}
})(current, previous);
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Mohammad Danish