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

ChrisBurks
Mega Sage

If only checking for one attachment on a Record Producer then there should be a tab on the Record Producer record called "Portal settings". Within this tab is a flag for making attachment mandatory.

ChrisBurks_0-1740431396279.png

 

I don't think that will work.  An attachment isn't always necessary, only under certain conditions.  I have no issue testing for those conditions, I just don't know how to have it check for an attachment in that case.

Ah I see. I missed the "under certain scenarios". Well, there have been many techniques on doing this and many stem from modifying and implementing this SN KB article: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743672

Step 3 has me a little concerned, customizing the Portal, especially since we are going to be moving to the Employee Service Center (esc) later this year.  We really do not want to customize these out-of-the-box things.

 

Is there no way to validate it without doing this customization of the portal?