- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Chandan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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
3 weeks ago
This is for a custom application record.
I found a solution by creating a custom field where I am propagating attachments along with counter logic for that field.
I am comparing the attachment count on both records. If the count is less than or equal to the propagated attachment count, then adding one more attachment is mandatory.
This is working. As a drawback of this approach, I have added a note: "Do not remove the propagated attachments" when attachments are already available and have been propagated from another record.
Adding a description or tags to attachments is not feasible using OOB functionality.
Thanks for your solution and response.
Chandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks 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
3 weeks 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