Validation on attachment format (.csv only) for service catalog item before submission

WilliamLKP
Tera Contributor

Hi there,

 

Trying to find a way to validate the file format for an attachment on a service catalog item before the user submits the item.  I was able to validate that one attachment only is submitted, but I can't validate the file format that the user attaches (content-type = 'text/csv').  I've seen some solutions for widget customization to get the cart ID, as well as other catalog client script methods in the ServiceNow community.  I'm on Washington version and every solution/workaround shared on the community seems to be unsupported or not working as suggested.  Anyone know of a proven solution or is there a known timetable to being able to solve reference of a cart ID per submission or validation of attached files on a service catalog item in the portal?   Much appreciated whatever you can offer!  Thank you! 

 

-WilliamLKP 

1 ACCEPTED SOLUTION

Anoja
Mega Sage

Hi @WilliamLKP ,

 

You can write on submit catalog client script

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (this.document.getElementsByClassName('get-attachment').length == 1) {
        var value = (this.document.getElementsByClassName('get-attachment')[0].innerHTML).toLowerCase();
        if (value.indexOf('.csv') > -1) {
            return true;
        } else {
            alert("Attachment should be in only CSVformat!");
            return false;
        }
    } else if (this.document.getElementsByClassName('get-attachment').length < 1) {
        alert("Attachment Required!!");
        return false;
    }
}
 
Thanks,
Anoja

View solution in original post

3 REPLIES 3

Sujatha V M
Kilo Patron
Kilo Patron

@WilliamLKP  Here is my implementation for validating the attachment type. 

 

1. Create a variable of type "attachment"

SujathaVM_0-1718115072652.png

 

2. Under Type Specifications tab, add the below to variable attributes. 

 

SujathaVM_1-1718115095511.png

 

Results: 

  • If the file type is not .csv format

SujathaVM_7-1718115284494.png

 

  • If the file type is .csv format

SujathaVM_6-1718115238084.png


Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Anoja
Mega Sage

Hi @WilliamLKP ,

 

You can write on submit catalog client script

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (this.document.getElementsByClassName('get-attachment').length == 1) {
        var value = (this.document.getElementsByClassName('get-attachment')[0].innerHTML).toLowerCase();
        if (value.indexOf('.csv') > -1) {
            return true;
        } else {
            alert("Attachment should be in only CSVformat!");
            return false;
        }
    } else if (this.document.getElementsByClassName('get-attachment').length < 1) {
        alert("Attachment Required!!");
        return false;
    }
}
 
Thanks,
Anoja

WilliamLKP
Tera Contributor

Thanks for the solutions!  I chose the onsubmit catalog client script, since that required the least amount of addition customer updates, but seems like they both will do the trick.  😀