File Attachment field type making mandatory via UI Policy not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 09:02 AM - edited 07-09-2024 09:03 AM
Hi Team,
At table level I have file attachment field. This field should be visible and mandatory based on other field value. I am making this field as mandatory and visible via UI policy.
So till here its working fine, file attachment is visible and becoming mandatory. but issue is, even after attaching attachment also, still it remain as mandatory and not allowing to submit the record.
So, can anyone help me on this please.
Not looking for the attachment icon solution here, because I have multiple file attachment fields, so.
Best Regards,
Pooja
Best Regards,
Pooja

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 09:35 AM
you'll need to write a script to validate whether an attachment has been added to the record
UI Policy > UI Policy Action > Client Script.
A) Add UI Policy Actions to set the file attachment field to mandatory and visible.
B) Add Client Script to Handle File Attachments.
onSubmit CS :
(function executeRule(current, previous /*null when async*/) {
var fileAttachmentField = 'your_attachment_field_name';
var isAttachmentMandatory = g_form.getValue('your_controlling_field') == 'your_controlling_field_value';
if (isAttachmentMandatory) {
var ga = new GlideAjax('CheckAttachment');
ga.addParam('sys_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
var attachmentExists = response.responseXML.documentElement.getAttribute("answer") == 'true';
if (!attachmentExists) {
g_form.addErrorMessage('Attachment is mandatory.');
g_form.showFieldMsg(fileAttachmentField, 'Attachment is mandatory.', 'error');
g_form.submitComplete = false;
} else {
g_form.submitComplete = true;
}
});
}
})(current, previous);
Script Include:
var CheckAttachment = Class.create();
CheckAttachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkAttachment: function() {
var sys_id = this.getParameter('sys_id');
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', sys_id);
gr.query();
return gr.next() ? 'true' : 'false';
}
});
If my answer helped you in any way, please then mark it as helpful or correct.