Skip to content

Instantly share code, notes, and snippets.

@mrjacobbloom
Created November 26, 2018 21:05
Show Gist options
  • Select an option

  • Save mrjacobbloom/7f94d6d9a66b513c6d57f6fa0964896d to your computer and use it in GitHub Desktop.

Select an option

Save mrjacobbloom/7f94d6d9a66b513c6d57f6fa0964896d to your computer and use it in GitHub Desktop.
Bookmarklets I use to make ServiceNow good
/* Get a markdown link to the current record
* Copies it to clipboard, adds nav stuff to URL if there isn't any
* Nice for Trello
* e.g. [INC123456](whatever.service-now.com/...)
*/
javascript:(() => { let copy = text => { let input = document.createElement('textarea'); input.textContent = text; document.body.appendChild(input); input.select(); document.execCommand("copy"); input.remove(); }; let navUrl = (() => { let [, path] = /^https:\/\/.+\.service-now\.com(.+)$/.exec(location.href) || []; return path && path.match(/^\/nav/) ? location.href : location.origin + `/nav_to.do?uri=${encodeURIComponent(path)}`; })(); let number = document.title.split('|')[0].trim(); let out = `[${number}](${navUrl})`; copy(out); return undefined; })();
/* Get code for a GlideRecord that gets the current record
* Copies it to clipboard so you can paste it into a BG script/Xplore/whatever
*/
javascript:(() => { let href = location.href; href = href.replace('nav_to.do', ''); let [, table, sys_id] = /([a-z_]+)\.do.*sys_id(?:=|%253D)([a-f\d]{32})/.exec(href); let out = `(function() {\n var ${table} = new GlideRecord('${table}');\n ${table}.get('${sys_id}');\n return ${table};\n})();`; let input = document.createElement('textarea'); input.textContent = out; document.body.appendChild(input); input.select(); document.execCommand("copy"); input.remove(); return undefined; })();
/* Toggle nav\
* Toggles between /nav_to.do?uri=... and /...
* There's probably a native way to do this in ServiceNow lol
*/
javascript:(() => { let navEncode = path => location.origin + `/nav_to.do?uri=${encodeURIComponent(path)}`; let navDecode = path => { let [, encoded] = (/nav_to\.do\?uri=(.+)$/.exec(path) || []); return encoded && decodeURIComponent(encoded); }; let navUrl = (() => { let [, path] = (/^https:\/\/.+\.service-now\.com(.+)$/.exec(location.href) || []); return path && path.match(/^\/nav/) ? navDecode(path) : navEncode(path); })(); if(navUrl) location.href = navUrl; })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment