Article

ServiceNow Tips and Tricks from Commands to Scripts

ServiceNow Tips and Tricks from commands to scripts from Milestone’s  Kenny Wimberly, ServiceNow Sr Solutions Architect. 

Kenny has shared with us a few helpful tips that he uses often.

Canceling a transaction

    • Area – whole platform
    • Type – browser URL command
    • <servicenow instance url>/cancel_my_transaction.do
    • What it does is stop a transaction that you have running on the front end. For example, you open a list of records (sys_audit, Syslog, task) that takes an incredible amount of time. Then, you attempt to cancel with the provided on-screen timer that allows you to cancel supposedly. Unfortunately, it does not work or hangs on “canceling.” This will allow you to override and cancel your long-running transaction.

Navigator commands (these are just the most common ones I use; send more later)

    • Area – Navigator
    • Type – Navigator shortcut command
    • Commands:
      • <table name>.filter – allows you to open a list view for a table and only show the filter. I use this for huge tables like task, sys_audit, Syslog, etc.

      • <table name>.FILTER – does the same as above but opens in a new tab
      • <table name>.do – opens a new record on the table. I use this when I need to circumvent the absence of a New button for a table list.

      • <table name>.list – opens a table list (everyone pretty much knows this one

Decoding a ServiceNow URL in the script

    • Area – Client-side Scripting
    • Type – Script
    • This is used to decode a ServiceNow URL, which is not necessarily possible by simply using a decoder because it’s encoded twice. Therefore you must decode it twice.
      • For example, you have a URL that looks like this: ‘https://instance.service-now.com/nav_to.do?uri=%2Fsc_req_item_list.do%3Fsysparm_query%3Dcat_item%253D7e4c1e001b90f450bdf62173b24bcb6f%255Estate!%253D3%255EORstate%253DNULL%26sysparm_first_row%3D1%26sysparm_view%3D’
      • If you want to get the cat_item sys_id by parsing the URL, you would not be able to decode the URL simply. Instead, you must double-decode to get the actual value. Initial decoding removes the URL encoding, but you must remove the ServiceNow encoding for the query parameter.
      • Sample script to do this:
        • var url = ‘https://instance.service-now.com/nav_to.do?uri=%2Fsc_req_item_list.do%3Fsysparm_query%3Dcat_item%253D7e4c1e001b90f450bdf62173b24bcb6f%255Estate!%253D3%255EORstate%253DNULL%26sysparm_first_row%3D1%26sysparm_view%3D’;
        • var urlx = decodeURIComponent(url);
        • gs.info(decodeURIComponent(urlx));
      • Now you have a clean URL for which you can parse the parameters and get the value you need

 

Keyboard Shortcut for javascript on-screen execution tool

      • Area – Internal SN UI (not portal)
      • Type – Keyboard shortcut
      • I use this to test certain client-side code or to manipulate forms for debugging.
      • Shortcut – ctrl+shift+j
      • This is great for using  in list views and form views

Getting all values of a GlideRecord in a server-side script:

  • Area – Server-side scripting
  • Type – Script
  • Purpose: When you need to pull all values from a GlideRecord into a client script or some other place that doesn’t have access to a dot-walk. This can be used in many scenarios.
  • Script:
    • //get all values of a GlideRecord
    • var gr = new GlideRecord(‘<table>’);
    • gr.get(‘<sys_id>’);
    • for (var i in gr) {
    •   gs.info(i + ‘:’ + gr[i]);
    • }
Facebook
Twitter
LinkedIn
Categories

Select a Child Category
category
67640eb4bedf2
1
0
226,352,350
Loading....
Recent Posts
Social Links

Related Posts

Want to Learn More?

Milestone experts take the time to listen, understand your needs, and provide the right mix of tools, technology, and resources to help you meet your goals.

Request a complimentary consultation to get started.

Request a Complimentary Consultation

Skip to content