- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
Hi @armanoj
Try this:
1: Create the Script Include
- Navigate to System Definition > Script Includes >Click New
- Name: checkApprovalAttachment
- Client callable: Check the box (true)
var chkApprovalAttachment = Class.create();
chkApprovalAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasAttachment: function() {
var approvalId = this.getParameter('sysparm_approval_id');
var grAttach = new GlideRecord('sys_attachment');
grAttach.addQuery('table_sys_id', approvalId);
grAttach.query();
if (grAttach.next())
{
return 'true';
}
return 'false';
},
type: 'chkApprovalAttachment'
});
2: Create the Client Script
Navigate to System Definition > Client Scripts>Click New
- Name: Mandatory Attachment on Approval
- Table: Approval [sysapproval_approver]
- Type: onSubmit
- UI Type: All
function onSubmit() {
var state = g_form.getValue('state');
if (state == 'rejected') {
return true;
}
var ga = new GlideAjax('chkApprovalAttachment');
ga.addParam('sysparm_name', 'hasAttachment');
ga.addParam('sysparm_approval_id', g_form.getUniqueValue());
var response = ga.getXMLWait();
var result = response.documentElement.getAttribute("answer");
if (result == 'false') {
g_form.addErrorMessage('An attachment is required before you can submit your approval.');
return false;
}
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti