How to verify Catalog Item request has attachment

chrish5
Giga Guru

I found the below script on different Community postings that checks to see if a Catalog Item request has an attachment.  I modified the "if" to match my variable so it checks that the Request Type variable is "Report Submission".  When I submit a test request with the Request Type variable set to "Report Submission" and with no attachment, the first alert is popping, so I know the "if" is working,, but after that I get a "There is a JavaScript error in your browser console" message and the request is submitted.  The developer console message states "ReferenceError: getSCAttachmentCount is not defined".  Can someone tell me what is wrong with the script?  

 

function onSubmit() {
    if(g_form.getValue('request_type') == 'report_submission'){
        alert("Request type is Report Submission");
        try {
            var attachments = document.getElementById('header_attachment_list_label');
            if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
                alert("You must attach the user security report before submitting this request");
                return false;
            }
        }
        //For Service Portal
        catch(e) {
            var count = getSCAttachmentCount();
            if(count <= 0) {
                alert("You must attach the user security report before submitting this request");
                return false;
            }
        }
    }      
    }
7 REPLIES 7

Marcos Kassak
Kilo Sage
Kilo Sage

Hi @chrish5,

 

I believe you do not need code to make your attachment mandatory:

 

MarcosKassak_0-1701897281285.png

 

At your Catalog Item, navigate into the Portal Settings tab and mark the Mandatory Attachment checkbox.

 

Let me know the results!

 

If you found my answer helpful or correct in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

Checking this makes an attachment mandatory no matter what.  I only need the attachment to be mandatory if the Request Type variable is "Report Submission".  

Make sense now, so what you can do without coding and using DOM (which is not very recommended).

 

You can create a variable with the type Attachment, and make it mandatory through UI Policy based on your conditions.

 

Variable configuration:

MarcosKassak_1-1701898596544.png

 

How it would be on Portal:

MarcosKassak_0-1701898509705.png

 

Let me know if this helps!

 

If you found my answer helpful or correct in any way, please don't forget to mark it to help future readers! 👍

 

--

 

Kind regards,


Marcos Kassak
Solution Consultant  🎯

Hi Marcos,

Thanks for continuing to provide assistance on this.  This is an excellent idea and works well with making at attachment required when the Request Type is "Report submission" but the down stream problem I am facing with this approach it the attachment does not get added to the approval notification that is the next step in this catalog items workflow.  If I add the attachment via the paper clip icon, the attachment does get added to the approval notification.  Having the attachment on the approval notification is needed for this process.  Any more thoughts on accomplishing this? 

 

Thanks,

Chris