Create a UI routing action

This solution enables you to create a record with the service desk without knowing whether it is an incident or request item; the service desk can then route the record to the appropriate table.

About this task

Note: Functionality described here requires the Admin role.

To create a UI routing action:

Procedure

  1. Create a new table that extends the task table (for example, New Call).
  2. Create a module to create a new New Call record.
  3. Create any fields that you want on the New Call table.

    The only fields you need are those fields necessary to determine whether the new call should route to an Incident or a Request Item. Ensure that the form contains any fields that you want to pass to the Incident or Request Item. In this example, the following are created on the form:

    • Requested for (reference)
    • Location (reference)
    • Call type (choice with two values--Incident and Request)
    • Request Item (reference to the sc_cat_item Item table)
  4. Add some UI policies to set a couple of fields to mandatory and hide the Request item field based on the Call type selection.
  5. Remove unnecessary buttons and functionality from the form.
  6. Create a new UI Action button. This button redirects the user to either an incident or a request. It also creates the incident record and copies values to the incident and the Request Item form.
    var reqItem = current.u_item;
    var requestedFor = current.u_requested_for;
    var location = current.location;
    
    if(current.u_incident_request == 'Incident'){
      //Create a new incident record and redirect to the new incident
      var rec = new GlideRecord('incident');
      rec.initialize();
      rec.caller_id = requestedFor;
      rec.location = location;
      rec.insert();
      action.setRedirectURL(rec);
    }
    
    if(current.u_incident_request == 'Request'){
      //Build the url and route the user to the request item
      var url = '';
      if(current.u_item.sys_class_name == 'sc_cat_item_guide'){
        url = 'com.glideapp.servicecatalog_cat_item_guide_view.do?sysparm_initial=true&sysparm_guide=' + 
          reqItem + '&sysparm_user=' + requestedFor + '&sysparm_location=' + location;
      }
      else{
        url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + reqItem + '&sysparm_user=' +  
          requestedFor + '&sysparm_location=' + location;
      }
      action.setRedirectURL(url);
    }
  7. The Route button in the preceding example passes the Requested for and Location values in the URL to the Request Item form. Ensure that you have variables called requested_for and location on your item, record producer, or order guide that map these values using the following client script. There is a limit as to how much information you can pass, as the URL has a restricted length. It is generally not a best practice to send information from long text fields using this method.
    function onLoad() {
      var url = document.location.toString();
      var userKey = 'sysparm_user=';
      var locKey = 'sysparm_location=';
      var userPosition = url.indexOf(userKey);
      var locPosition = url.indexOf(locKey)
      if (userPosition != -1) {
        var user = url.substr(userPosition+userKey.length, 32);
        g_form.setValue('requested_for',user);
      }
      if (locPosition != -1) {
        var loc = url.substr(locPosition+locKey.length, 32);
        g_form.setValue('location',loc);
      }
    }