catalog attachment when submitting the request on portal.

varma2
Mega Sage

Hi All,

 

We have requirement when we submit the request from portal for specific catalog item Attachment is mandatory. But  attachment should be a TEXT or  Sql.

validates the attachment it would be either .txt or .sql and content should be available.

 

please help me how can we achieve this requirment.

 

Thanks,

Varma 

2 ACCEPTED SOLUTIONS

Hi @Sohail Khilji ,

 

Thanks for the solution.

I got the error while creating onload client script. Im not able to identify the what mistake on the script.

Please suggest.

 

varma2_0-1715856599256.png

Thanks,

Varma

View solution in original post

remove the try block keep the script only within onLoad function.


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

View solution in original post

3 REPLIES 3

Sohail Khilji
Kilo Patron
Kilo Patron

 

Hi @varma2 ,

 

Create  onsubmit client script which validates the file which is loaded.

 

 

function onSubmit() {
    // Type appropriate comment here, and begin script below
    var arr = [];
    var extensions = ['.txt','.sql'];
    try {
        var names = this.document.getElementsByClassName('get-attachment ng-binding ng-scope');
        if (names.length === 0) {
            alert('Please attach at least one file.');
            return false;
        }

        for (var i = 0; i < names.length; i++) {
            var val = names[i].innerHTML;
            arr.push(val.toString());
        }

        for (var j = 0; j < arr.length; j++) {
            var isValid = false;
            for (var k = 0; k < extensions.length; k++) {
                if (arr[j].indexOf(extensions[k]) !== -1) {
                    isValid = true;
                    break;
                }
            }
            if (!isValid) {
                alert('Please give files with one of the following extensions: ' + extensions.join(', '));
                return false;
            }
        }
    } 
}

 

OR >

 

You can create a script include and a onsubmit client scirpt using ajax call you can validate the type of file attached to the catlaog before submission,

 

 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Hi @Sohail Khilji ,

 

Thanks for the solution.

I got the error while creating onload client script. Im not able to identify the what mistake on the script.

Please suggest.

 

varma2_0-1715856599256.png

Thanks,

Varma

remove the try block keep the script only within onLoad function.


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect