Hi James,
Use below code:
------------------------
var ATTACHMENT_BINDING = 'my:Attachment_1';
var CONTROLLING_FIELD_PATH = '/my:myFields/my:field_4';
var REQUIRED_TRIGGER_VALUE = 'X';
var matchingAttachmentSpans = $j('span[binding="' + ATTACHMENT_BINDING + '"]');
var attachmentControl = $j(matchingAttachmentSpans[0]);
// ─── Read the Controlling Field Value ─────────────────────────────────────────
// Retrieve the current value of the field that determines attachment requirement
var controllingFieldValue = $form.getValue(CONTROLLING_FIELD_PATH);
if (controllingFieldValue === REQUIRED_TRIGGER_VALUE) {
SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 2;
attachmentControl.find('input[type=file]').addClass('frm_required_error');
Utils.addMessageToControl(attachmentControl);
if(attachmentControl[0].innerText.match(/change/g).length <2 )
{
$j.alert('Attachment should contain Change in Attachment Name');
}
else {
const text = attachmentControl[0].innerText;
const files = text.match(/C:\\fakepath\\[^\s]+/g) || [];
const allValid = files.every(file => /\.(pdf|zip)$/i.test(file));
if (!allValid) {
$j.alert('Attachment should only contain .pdf or .zip files');
}
else
{
SVFormDoSetActionsAndSubmit(5,'TODO_ButtonId');
}
}
}
else {
SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 0;
attachmentControl.parents('div:first').find('.text-danger').remove();
attachmentControl.find('input[type=file]').removeClass('frm_required_error');
SVFormDoSetActionsAndSubmit(5,'TODO_ButtonId');
}
--------------------------------
Explanation: Above code checks for minimum of two attachments in the attachment control and checks all attachments should only of type .pdf or .zip
code snippet for .pdf and .zip files:
-----------
else {
const text = attachmentControl[0].innerText;
const files = text.match(/C:\\fakepath\\[^\s]+/g) || [];
const allValid = files.every(file => /\.(pdf|zip)$/i.test(file));
if (!allValid) {
$j.alert('Attachment should only contain .pdf or .zip files');
}
-------------------
This can be further modified to include more file types, or allow other file types.
Hope this helps.
Regards
------------------------------
Hammad Naeem
*Precisely Software Inc.
------------------------------
Original Message:
Sent: 04-06-2026 05:07
From: James Polley
Subject: Tip of the Week - Attachment Control and how to make it mandatory
Hammad, How would I change this code to check for file type. I want to only allow PDF and ZIP type files in this attachment control. How would I do that?
------------------------------
James Polley
RAYTHEON COMPANY
------------------------------
Original Message:
Sent: 04-02-2026 07:24
From: Hammad Naeem
Subject: Tip of the Week - Attachment Control and how to make it mandatory
Hi Ed,
The trick is to use a custom button to SaveAndRoute / Complete the task, use below code on Custom Button:
----------------------------
var ATTACHMENT_BINDING = 'my:Attachment_1';
var CONTROLLING_FIELD_PATH = '/my:myFields/my:field_4';
var REQUIRED_TRIGGER_VALUE = 'X';
var matchingAttachmentSpans = $j('span[binding="' + ATTACHMENT_BINDING + '"]');
var attachmentControl = $j(matchingAttachmentSpans[0]);
// ─── Read the Controlling Field Value ─────────────────────────────────────────
// Retrieve the current value of the field that determines attachment requirement
var controllingFieldValue = $form.getValue(CONTROLLING_FIELD_PATH);
if (controllingFieldValue === REQUIRED_TRIGGER_VALUE) {
SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 2;
attachmentControl.find('input[type=file]').addClass('frm_required_error');
Utils.addMessageToControl(attachmentControl);
if(attachmentControl[0].innerText.match(/change/g).length <2 )
{
$j.alert('Attachment should contain Change in Attachment Name');
}
else {SVFormDoSetActionsAndSubmit(5,'TODO_ButtonId');}
}
else {
SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 0;
attachmentControl.parents('div:first').find('.text-danger').remove();
attachmentControl.find('input[type=file]').removeClass('frm_required_error');
SVFormDoSetActionsAndSubmit(5,'TODO_ButtonId');
}
------------------------------------
Explanation:
Above Code sets minimum attachments required = 2, if field_4 value is 'X',
further it checks if the attachments provided have atleast two attachment containing 'change' in their name, if it is satisfied the form will move forward, otherwise it will give you error: 'Attachment should contain Change in Attachment Name'
You can modify below condition and display message in above code as per your requirement.
------------
if(attachmentControl[0].innerText.match(/change/g).length <2 )
{
$j.alert('Attachment should contain Change in Attachment Name');
}
----------
Regards
------------------------------
Hammad Naeem
*Precisely Software Inc.
Original Message:
Sent: 03-31-2026 02:01
From: Ed Meiners
Subject: Tip of the Week - Attachment Control and how to make it mandatory
hi,
Is there a way to check whether the correct kind (part of name for example) of documents are attached?
This is an actual use case we have. Fictive example, at minimum a document containing in the name "...ContractType ABC..." must be attached.
(potentially not just one document with a specific name but more (like 2 or 3)).
Thanks.
------------------------------
Ed Meiners
Lead Consultant MDIM
Wessanen Nederland Holding BV
Amsterdam