attachment mandatory requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour 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
36m ago - last edited 36m 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 description 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.addNullQuery('description');
attGr.query();
while (attGr.next()) {
attGr.description = "COPIED_ATTACHMENT";
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 desc = attGr.getValue('description') || '';
if (desc.indexOf('COPIED_ATTACHMENT') === -1) {
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