ServiceNow - Reference direct link to record

Add a direct link button to reference fields in forms

目前為 2024-01-18 提交的版本,檢視 最新版本

// ==UserScript==
// @name         ServiceNow - Reference direct link to record
// @version      0.0.2
// @description  Add a direct link button to reference fields in forms
// @author       Matteo Lecca
// @match        *.service-now.com/*.do*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=service-now.com
// @grant        none
// @license MIT
// @namespace    https://greasyfork.org/users/1246673
// ==/UserScript==

(function() {
    'use strict';

    let referenceList = document.querySelectorAll("button[data-type='reference_popup']:not([style*='display: none'])");
    
    referenceList.forEach(referenceField => {
        let table = referenceField.dataset.table;
        let field = referenceField.dataset.ref;
        let form = referenceField.dataset.form;
        let recordId = g_form.getValue(field);

        let buttonLink = document.createElement('a');
        buttonLink.title = '[WK - SN] Direct link to record';
        buttonLink.href = 'https://' + window.location.hostname + '/' + form + '?sys_id=' + recordId;
        buttonLink.classList.add('btn', 'btn-info', 'btn-ref', 'icon', 'icon-arrow-right');

        referenceField.parentNode.parentNode.append(buttonLink);
    });

})();