Service Catalog Attachment

AnilJ
Tera Contributor

I have a requirement where there is an attachment type field(e.g.,  diso_approval) if it contains only .msg file then submit the request; otherwise unable to submit form.

Note: Variable Atrribute not working( Need a script). 

1 ACCEPTED SOLUTION

@AnilJ 

seems your form doesn't have that field

add this from list in the variable attributes for that variable allowed_extensions=msg

AnkurBawiskar_0-1740049639227.png

From list you can add if you don't want to make any form layout

AnkurBawiskar_1-1740049680965.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Vishwa Pandya19
Mega Sage

Hello @AnilJ ,

 

Below link should be able to help you:

https://www.servicenow.com/community/itsm-forum/check-attachment-file-type-client-script/m-p/619137

If my answer has helped you in any way please mark it as correct or helpful.

Pooja58
Kilo Sage

Hi @AnilJ ,

Try below onSumbit catalog client script.


function onSubmit() {
    // Get the file upload variable (replace 'file_variable_name' with the actual name of the file upload variable)
    var fileVar = g_form.getValue('file_variable_name');  // Ensure this is the variable name of your file upload field

    // Check if a file has been uploaded
    if (fileVar) {
        // Get the file extension (get the part after the last dot in the filename)
        var fileExtension = fileVar.split('.').pop().toLowerCase();

        // If the file extension is not '.msg', show an error message
        if (fileExtension !== 'msg') {
            g_form.showFieldMsg('file_variable_name', 'Please upload a valid .msg file.', 'error');
            return false; // Prevent form submission
        }
    }

    // If the file is valid, allow the form submission
    return true;
}

 

 

Please mark as Correct/helpful or accepted solution if it solves your issue.

 

Best Regards,

Pooja

Ankur Bawiskar
Tera Patron
Tera Patron

@AnilJ 

variable attributes should work

share what did you configure and what's not working?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Please find below SS, unable to see variable attribute refer SS.

AnilJ_0-1740048906301.png