Making an attachment mandatory in a catalog item

SK41
Giga Guru

Hi,

 

I have a requirement to make the attachment mandatory on the catalog item. User does not use service portal, so I cannot use "mandatory checkbox" in the catalog. My requirement is to check if the user has attached the file before submitting the catalog. If not, show them error message "Please attach a file".

 

How can I achieve that?

Thanks!

1 ACCEPTED SOLUTION

Hi Anurag,

 

I used below code in onSubmit catalog client script and it worked for me:

 

var count = getCurrentAttachmentNumber();
    if(count == 0){
        g_form.addErrorMessage('You must add an attachment');
        return false;
    }

 

View solution in original post

17 REPLIES 17

Hi, 

I am geting below error when trying to use the above code in onSubmit client script:

onSubmit script error: TypeError: Cannot read properties of null (reading 'getElementById'):
function () { [native code] }

 

Could you please let me know if I am missing anything here?

 

My catalog item is in a scoped application and I have created a module through which the user will access the catalog.

Hi @SK41 

 

Please set Isolate Script to False to make the script suggested by @Anurag Tripathi  work as it requires DOM manipulation.

 

Thanks & Regards
Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

It is false only, still getting the error. Could it be because of scoped application?

 

Do I need to create any other script as well other than onSubmit to make it work?? Right now, I have just created the onSubmit script which @Anurag Tripathi  shared.

 

Can you show a screenshot of your script?

Here is a sample I tested on

AnuragTripathi_0-1704884991430.png

 

-Anurag

Hi Anurag,

 

I used below code in onSubmit catalog client script and it worked for me:

 

var count = getCurrentAttachmentNumber();
    if(count == 0){
        g_form.addErrorMessage('You must add an attachment');
        return false;
    }