Automate

 View Only
  • 1.  Tip of the Week - Attachment Control and how to make it mandatory

    Employee
    Posted 21 days ago
    Edited by Rishav Kumar 21 days ago

    The Attachment Control in Precisely Automate Evolve forms enables users to upload files as part of the form submissions. It's critical for processes requiring supporting documents like contracts, certificates, or compliance evidence. The documents attached to the form can also be uploaded to SAP.

    Overview

    • Allows single or multiple file uploads.
    • Supports common file types: PDF, DOCX, XLSX, images, etc.
    • Files are stored securely and linked to the workflow instance.


    Attachment Control Properties

    Property

    Description

    Allow Deletion

    Enables the deletion of files that have been uploaded previously.

    Allow Replacement

    Enables the replacement of files that have been uploaded previously. If set to false, the uploaded files cannot be replaced.

    Allow Update

    Enables the updating of files.

    Hide Existing

    Hides the attachments that have been uploaded previously.

    Include Inline

    Allows the attachments in the form to be displayed inline in the form.

    Require Review

    Requires that the user click the attachments and view them before proceeding.

    Maximum

    The maximum number of attachments that are required before the form can be submitted.

    Minimum

    The minimum number of attachments required for the form to be submitted.

    Message

    The message to display if the minimum or maximum requirement is not met.

    Inline Width

    Defines the width of the window in which the attachment is displayed. Used if Include Inline is set to true.

    Inline Height

    Defines the height of the window in which the attachment is displayed. Used if Include Inline is set to true.

    Attachment control also respects the following Configuration Options/Keys: 

    ·       AttachmentControlValidationType – Standard behavior searches the file name for known illegal characters, and then present an error if a file name contains those characters.

    Custom retrieves a regular expression from the AttachmentControlValidationRegExp key, and if that regular expression does not match the file name, presents the error to the end user.

    Important: The TYPE must be specified in lower case, i.e. standard or custom.

    ·       AttachmentControlValidationRegExp – Regular expression to use with custom Attachment Control validation. Defaults value is ^([a-zA-Z0-9_ ]+\.?)+$

    If you are using the Attachment Control Upload Document to SAP, then make sure the Attachment Control is part of Repeating Table (having FILE_BYTES column). Attachment Control to upload document to SAP cannot be placed outside Repeating Table, as binding of non-repeating and repeating field cannot be same, for example FILE_BYTES.

    Making Attachment Mandatory

    Example 1: Set a minimum of 1 and maximum of 4 attachments in the form.

    Set the value of property "Minimum" as 1

    Set the value of property "Maximum" value as 4

    Set the Message property as "Minimum 1 and Maximum 4 attachments are allowed"

     

    Example 2: Conditionally set the Attachment Control 'my:Attachment_1' to have a minimum of 1 attachment if the value of field  '/my:myFields/my:field_4' is X

    var ATTACHMENT_BINDING = 'my:Attachment_1';
    var CONTROLLING_FIELD_PATH = '/my:myFields/my:field_4';
    var REQUIRED_TRIGGER_VALUE = 'X';


    var fieldValue = $form.getValue(CONTROLLING_FIELD_PATH);


    if (fieldValue === REQUIRED_TRIGGER_VALUE)
    {

    SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 1;

    }


    Example 3: Conditionally set the Attachment Control 'my:Attachment_1' to have a minimum of 1 attachment if the value of field  '/my:myFields/my:field_4' is X, else set the minimum attachment value as 0. Also suppress the popup message that appears because of form validation when no attachments are added.


    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]);

    var controllingFieldValue = $form.getValue(CONTROLLING_FIELD_PATH);

    if (controllingFieldValue === REQUIRED_TRIGGER_VALUE) {

    SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 1;

    attachmentControl.find('input[type=file]').addClass('frm_required_error');

    Utils.addMessageToControl(attachmentControl);

    }

    else {

    SVFormInternalAttachmentValidations[ATTACHMENT_BINDING].minimum = 0;

    attachmentControl.parents('div:first').find('.text-danger').remove();

    attachmentControl.find('input[type=file]').removeClass('frm_required_error');

    }

     

    Usage Scenarios:

    • Vendor onboarding: Require tax certificates
    • Material Master: Safety datasheet mandatory for hazardous materials.
    • Finance Requests: Approval memo for high-value transactions.

    Tips & Tricks

    • Apply conditional mandatory only where business logic demands.
    • Restrict file types to avoid security risks; use configuration keys.
    • Provide error messages for missing attachments.
    • Test rules thoroughly to avoid blocking submissions.
    • Conditional logic errors can prevent form submission.
    • Performance impact: Multiple large attachments slow down form load.

      Best Practices

      • Keep file size limits reasonable (5–10 MB).
      • Use naming conventions for uploaded files.
      • Validate mandatory conditions in both UI and workflow logic.
      • Document rules for audit and troubleshooting



      ------------------------------
      Rishav Kumar
      Product Manager
      *Precisely Software Inc.
      ------------------------------



    • 2.  RE: Tip of the Week - Attachment Control and how to make it mandatory

      Posted 20 days ago

      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
      ------------------------------



    • 3.  RE: Tip of the Week - Attachment Control and how to make it mandatory

      Employee
      Posted 18 days ago

      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');
      }
      ----------
      Please find a working copy of the solution attached here: https://nowtransfer.de/24561a9253af

      Hope this helps.

      Regards


      ------------------------------
      Hammad Naeem
      *Precisely Software Inc.
      ------------------------------



    • 4.  RE: Tip of the Week - Attachment Control and how to make it mandatory

      Posted 14 days ago

      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
      ------------------------------



    • 5.  RE: Tip of the Week - Attachment Control and how to make it mandatory

      Employee
      Posted 14 days ago

      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.
      ------------------------------



    • 6.  RE: Tip of the Week - Attachment Control and how to make it mandatory

      Posted 13 days ago

      Thanks a lot Hammad!

      I am going to try this and play with it.



      ------------------------------
      Ed Meiners
      Lead Consultant MDIM
      Wessanen Nederland Holding BV
      Amsterdam
      ------------------------------