attachment mandatory requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
which form is this? screenshots please
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 23 seconds ago
Hi @SD_Chandan
Try this:
1: Flag Copied Files (Server-Side)
When your script or Flow copies attachments (using GlideSysAttachment.copy()), you must immediately add a marker to their File Name field. Update the Business Rule, Script Action, or Flow that performs the copy to include this logic
var sourceTable = 'incident';
var sourceSysId = 'SOURCE_SYS_ID_HERE';
var forCopyAtt = new GlideSysAttachment();
forCopyAtt.copy(sourceTable, sourceSysId, current.getTableName(), current.getUniqueValue());
var attGr = new GlideRecord('sys_attachment');
attGr.addQuery('table_name', current.getTableName());
attGr.addQuery('table_sys_id', current.getUniqueValue());
attGr.addQuery('file_name', 'NOT LIKE', '[Copied] %');
attGr.query();
while (attGr.next()) {
attGr.file_name = "[Copied] " + attGr.file_name;
attGr.update();
}
2: Create a Script Include (Server-Side Validation)
- Name: AttachmentValidationUtils
- Client Callable: True (Checked)
var AttachmentValidationUtils = Class.create();
AttachmentValidationUtils.prototype = Object.extendsObject(AbstractScriptProcessor, {
hasNewUpload: function() {
var recordId = this.getParameter('sysparm_record_id');
var tableName = this.getParameter('sysparm_table_name');
if (!recordId || !tableName) return 'false';
var attGr = new GlideRecord('sys_attachment');
attGr.addQuery('table_name', tableName);
attGr.addQuery('table_sys_id', recordId);
attGr.query();
if (!attGr.hasNext()) {
return 'false';
}
while (attGr.next()) {
var fileName = attGr.getValue('file_name')
if (fileName.indexOf('[Copied] ') !== 0)
{ return 'true'; }
}
return 'false';
},
type: 'AttachmentValidationUtils'
});
3: Create an onSubmit Client Script (Portal & Workspace Compatible)
- Type: onSubmit
- UI Type: All
function onSubmit() {
if (g_form.isNewRecord()) {
return true;
}
if (g_scratchpad.isAttachmentValid === true) {
return true;
}
var ga = new GlideAjax('AttachmentValidationUtils');
ga.addParam('sysparm_name', 'hasNewUpload');
ga.addParam('sysparm_record_id', g_form.getUniqueValue());
ga.addParam('sysparm_table_name', g_form.getTableName());
ga.getXMLAnswer(function(answer) {
if (answer === 'true') {
g_scratchpad.isAttachmentValid = true;
g_form.submit();
} else {
g_form.addErrorMessage('Submission blocked: You must upload at least one NEW attachment. Copied files do not satisfy this requirement.');
}
});
return false;
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
41m ago
I couldn't find a description field on the sys_attachment table.
Could you please point me to the field if it's available in your instance?
I couldn't find it in my PDI but your script mentions to use that
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader