The CreatorCon Call for Content is officially open! Get started here.

Verify a File is Attached to a Record Producer on the Service Portal

jmiskey
Kilo Sage

On our Service Portal, we have a Record Producer that creates a SAFE Epic (sn_safe_epic) record.  Through integration, these records are being transferred over to Azure DevOps upon submission into ServiceNow.

 

The issue is that under certain scenarios, the users are required to attach a file to the Record Producer record on the Service Portal before submitting.  We want to not allow them to submit the request if they have not attached any required files.

 

Unfortunately, it does not appear that we can use the "Attachment" field type on the Record Producer, as for some reason, ServiceNow will not send these attachments over to Azure Dev Ops.  However, if we use the out-of-the-box "Add Attachments" link at the bottom of all forms on the Service Portal, ServiceNow will send over those attachments to Azure Dev Ops.  

 

We are fine with doing that, but how can we create a Catalog Client Script to verify that they have actually attached a file before allowing them to submit?

 

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jmiskey 

you can use this onSubmit catalog client script and it will work in both native + portal

Example: if variable ABC has value as XYZ then make the attachment mandatory

Please enhance it as per your requirement

function onSubmit() {
    //Type appropriate comment here, and begin script below
	var variableValue = g_form.getValue('ABC');
    try {
        if (window == null) {
            // portal
            if (this.document.getElementsByClassName('get-attachment').length == 0 && variableValue == 'XYZ') {
                alert('You must add attachment before submitting this request.');
                return false;
            }
        }
    } catch (ex) {
        // native view
        var length = getSCAttachmentCount();
        if (length == 0 && variableValue == 'XYZ') {
            alert('You must add attachment before submitting this request.');
            return false;
        }
    }
}

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

15 REPLIES 15

Thanks, but we are going with Ankur Bawiskar's solution since it works for us, and is self-contained to the Catalog Client Script.