Blog

Service Portal: Require attachments

How can you require attachments on a catalog item in the Service Portal (SP)?

Unfortunately you can't just use the Client Script you used in the old CMS site right? The old DOM manipulation scripts used in CMS often won't work in the SP. as it is a different architecture than CMS.

How to require attachments in SP

1. Add a UI Script

  1. In the Left Navigator Bar, go to System UI > UI Scripts

  2. Click New

UI Script: GlobalCatalogItemFunctions
UI Type: All
Application: Global
Active: true

Script:
function getSCAttachmentCount() {
var length;
try {
length = angular.element("#sc_cat_item").scope().attachments.length;
//Use this line instead for Order Guides
//length = angular.element("#sc_cat_item_guide").scope().attachments.length;
} catch(e) {
length = -1;
}
return length;
}

2. Add a JS Theme

  1. In the Left Navigator Bar, go to Service Portal > Portals

  2. Click the Portal you want to adjust. It maybe be the one with URL suffix of "sp".

  3. Click the "info" button for the Theme. The standard theme is "Stock" or “La Jolla”

  4. Scroll to the bottom to the JS Include Related List

  5. Add your JS Include there

Create New JS Theme
Display Name: GlobalCatalogItemFunctions
UI Script: GlobalCatalogItemFunctions

3. Create a Catalog Client Script

For your catalog item you want to require attachments, use this client script.

Set the Isolate Script checkbox to false for this script. You may need to add it to the client script form to see the checkbox.

Name: Require Attachment
UI Type: All
Type: onSubmit
Isolate Script: false

function onSubmit() {
//Works in non-portal ui
try {
var attachments = document.getElementById('header_attachment_list_label');
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none' ) {
alert('You must attach a document before submitting this request.');
return false;
}
}
//For Service Portal
catch(e) {
var count = getSCAttachmentCount();
if(count <= 0) {
alert('You must attach a document before submitting this request.');
return false;
}
}
}

4. Scoped Application

If you are having trouble getting this to work with a scoped application.

  1. Switch to the scoped application

  2. Add System Property

    • Suffix: glide.script.block.client.globals

    • Type: string

    • Value: false

  3. Click Submit