Quantcast
Channel: Blog - ServiceNow Elite
Viewing all articles
Browse latest Browse all 191

Service Portal: Require attachments

$
0
0

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

Global: true
Script:
function getSCAttachmentCount() {
  var length;
  try {
  length = angular.element("#sc_cat_item").scope().attachments.length;
  } catch(e) {
  length = -1;
  }
  return length;
}

2. Add a JS Theme

pastedImage_2.png
  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"
  4. 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.

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 the completed form before submitting this request.');
  return false;
  }
  }
  //For Service Portal
  catch(e) {
  var count = getSCAttachmentCount();
  if(count <= 0) {
  alert('You must attach the completed form before submitting this request.');
  return false;
  }
  }
}

Viewing all articles
Browse latest Browse all 191

Trending Articles