How do you call out looking for an attachment in a catalog client script onSubmit

NadiaR
Tera Contributor
 
6 REPLIES 6

briannice
Kilo Sage

Hello @NadiaR 

 

I use the following onSubmit catalog client script on one of my record producers, let me know if it helps.

 

function onSubmit() {
    // Get attachment count
    var attachmentListElement = this.document.getElementsByClassName("get-attachment");
    var attachmentCount = attachmentListElement.length;

    // Add an error message if there are no attachments and cancel submit
    if (attachmentCount == 0) {
        getMessage("Please add an attachment", function (msg) {
            g_form.addErrorMessage(msg);
        });
        return false;
    }
}

 

Let me know if this works!

 

Kind regards,

Brian

NadiaR
Tera Contributor

Hi Brian!

 

The above worked thank you but, the message still displays when an attachment does exists. Here is the code I'm using. Do I need to change my if statement?

 

function onSubmit() {
    // Get the value of the 'type_of_toll_free_request' field and check for attachments
    var tollfree = g_form.getValue('type_of_toll_free_request');
    var attachmentListElement = this.document.getElementsByClassName("get-attachment");
    var attachmentCount = attachmentListElement.length;
 
        // Check if the 'type_of_toll_free_request' value is 'existing'and if attachment is attached.
        if (tollfree === 'existing' && attachmentCount == 0) {
            // Add an error message to notify the user
            alert('This type of request requires a signed LOA. If not attached, a member of the Telcom team will contact you.');

            // Return true to allow form submission if the condition is not met
            return true;
        }
   
}

 

Thanks,

Markus Kraus
Kilo Sage

You need to return false instead of true in your script.

 

By the way: Why don't you add a Variable of Type Attachment and make it mandatory? This would make such a script obsolete...

I hear ya but, they want the client to be able to still submit the request. Thanks for the feedback though.