Notifications

40 views

Description

Description

This article provides instruction on modifying links in a Simple List widget in Service Portal to open in a new browser tab. In order to accomplish this the "$window" Angular service is added to the client controller and the link URL is constructed and passed to the $window service with the "_blank" target attribute.

Procedure

The attached XML file (sp_widget_b0308d89205233004e82c59ab19f5b2b.xml) contains the widget complete with the modifications detailed below and can be downloaded and imported into your instance.

  1. Clone the OOB Simple List widget
  2. Add the $window Angular service
    • Add "$window" to the parameter list in the main function definition in the Client controller
    • Assuming the latest OOB version of the widget in Madrid is being used, the parameter list after this change: function ($scope, $location, $rootScope, spUtil, $interpolate, $window) {
  3. Parse the "url" object to build the URL to pass to the $window service
    • The "url" object contains four properties: id, sys_id, table and view
    • the "id" property refers to the portal page that is set in the "Link to this page" field in the instance options
    • The 'sys_id" property is the sysID of the linked record
    • The "table" property is the the name of the table to which the linked record belongs
    • The "view" property is the form view value set in the "View" field in the instance options and defaults to "sp"
    • The value of "$location.path()" which returns a forward slash and the portal suffix is prepended to a string formed by combining the values of the "url" object property values
    • The final string value: $location.path() + "?id=" + url.id + "&table=" + url.table + "&sys_id=" + url.sys_id + "&view=" + url.view
  4. Modify the onClick event function definition
    • Locate the onClick function definition in the client controller that begins on line 7 and modify the else if condition as follows
    • This block of script:
        } else if (url && typeof url == "object")
          $location.search(url);
        else {

      becomes:
        } else if (url && typeof url == "object") {
          var newURL = $location.path() + "?id=" + url.id + "&table=" + url.table + "&sys_id=" + url.sys_id + "&view=" + url.view;
          $window.open(newURL,"_blank");
        } else {

Applicable Versions

This article uses the Simple List widget available in the Madrid Patch 4 release.

Additional Information

***Disclaimer: implementing this functionality is considered customization and is not supported by ServiceNow. Use at your own risk! ***

Article Information

Last Updated:2019-08-02 20:39:03
Published:2019-07-17