If you’ve used the two-step catalog checkout before you’ve noticed the few fields on the final checkout screen. Users can provide information about the Requester and their location, along with some special instructions for the processing of the request. These fields are all optional however, so there’s no way to force a user to fill any of this information out. If you did need to force one or more of these fields to be mandatory, you could accomplish this by making a couple of modifications to the ‘servicecatalog_cart_template’ UI Macro.

Service Catalog Checkout Man Field


Because we’re working in the Service Catalog interface, making a field mandatory will work a little bit differently than in other places in the system. For this modification we will intercept the submission of the form and check each field to see whether it is empty or not. This can be done by making changes to the following lines in the ‘servicecatalog_cart_template’ UI Macro.

This solution requires a modification to an out-of-box UI Macro. While it may be necessary or desirable in your environment, just be aware that once you modify it, you own it! ServiceNow doesn’t upgrade (but will support) records updated from their out-of-box config.

–In the ‘servicecatalog_cart_template’ UI Macro, change the onClick event of the submit button in this line…

<button class="catalog catalog_next" type="submit" value="sysverb_insert" onClick="return gsftSubmit(this);" id="sysverb_insert">

to this…

<button class="catalog catalog_next" type="submit" value="sysverb_insert" onClick="return checkMandatorySubmit(this);" id="sysverb_insert">

–Note that in Eureka instances of ServiceNow you’ll be changing this line…

<a href="#" class="request_catalog_button" type="submit" value="sysverb_insert" onClick="return gsftSubmit(this);" id="sysverb_insert">

to this…

<a href="#" class="request_catalog_button" type="submit" value="sysverb_insert" onClick="return checkMandatorySubmit(this);" id="sysverb_insert">

–Add the ‘checkMandatorySubmit-CatalogCheckout’ global UI script function by navigating to ‘System UI -> UI Scripts’. You can modify this function to check any field(s) on the checkout form.

This UI Macro script can be pasted directly into the ‘servicecatalog_cart_template’ UI Macro to make the ‘Special Instructions’ field mandatory on checkout.

‘checkMandatorySubmit-CatalogCheckout’ global UI script
Name: checkMandatorySubmit-CatalogCheckout
Script:

function checkMandatorySubmit(){
   var manFields = '';
   var si = gel('special_instructions').value;
   if(si == ''){
      manFields = 'Special Instructions';
   }
   if(manFields == ''){
      gsftSubmit($('sysverb_insert'));
   }
   else{
      alert('The following mandatory fields are not filled in: ' + manFields);
      return false;
   }
}



Here’s another example UI script that makes the ‘Requested for’ field mandatory for ‘ITIL’ users.

‘checkMandatorySubmit-CatalogCheckout’ global UI script
Name: checkMandatorySubmit-CatalogCheckout
Script:

function checkMandatorySubmit(this){
   var manFields = '';
   var si = gel('sc_cart.requested_for').value;
   if(si == ''){
      manFields = 'Requested for';
   }
   if(g_user.hasRole('itil')){
      if(manFields == ''){
         gsftSubmit($('sysverb_insert'));
      }
      else{
         alert('The following mandatory fields are not filled in: ' + manFields);
         return false;
      }
   }
   else{
      gsftSubmit($('sysverb_insert'));
   }
}