Netsuite:如何在导航栏或页眉添加自定义链接?

问题描述 投票:2回答:1

有什么方法可以自定义导航栏或页眉,使其具有自定义链接?

使用情况是,我有一个JIRA问题收集器,是由javascript驱动的。 我希望用户能够从他们有问题的页面中提供反馈。然而,到目前为止,我所能想到的任何解决方案都会让用户离开当前页面。

举个例子,我有一个能把用户带离的例子。

  1. 我目前有一个Suitelet在其中一个菜单中。 该Suitelet调用了javascript,但即使如此,用户也被带走了。
  2. 我有一个工作流程 case 记录,在一个基于UI的动作的条件中调用一些Javascript Javascript被调用。与#1类似,但在case记录上。

我想我需要为我公司的域名创建并公开一个chrome扩展,只是为了让一个普适的javascript在所有页面上运行......似乎是一个大锤。

netsuite suitescript2.0
1个回答
0
投票

我希望有人能证明我是错的,但据我所知,没有办法将Javascript或任何东西注入NetSuite headernavbar--他们不提供自定义headernavbar。

我只好创建了一个Userscript,通过以下方式加载 暴力猴子 延长 浏览器火狐.

用户脚本模板示例

// ==UserScript==
// @name        NetSuite Mods (Example)
// @namespace   Violentmonkey Scripts
// @match       *.netsuite.com/*
// @include     *.netsuite.com/*
// @grant       GM_addStyle
// @version     1.0
// @author      Kane Shaw - https://stackoverflow.com/users/4561907/kane-shaw
// @description 6/11/2020, 6:25:20 PM
// ==/UserScript==


// Get access to some commonly used NLAPI functions without having to use "unsafeWindow.nlapi..." in our code
// You can add more of these if you need access to more of the functions contained on the NetSuite page
nlapiSetFieldText = unsafeWindow.nlapiSetFieldText;
nlapiSetFieldValue = unsafeWindow.nlapiSetFieldValue;
nlapiGetFieldText = unsafeWindow.nlapiGetFieldText;
nlapiGetFieldValue = unsafeWindow.nlapiGetFieldValue;
nlapiSearchRecord = unsafeWindow.nlapiSearchRecord;
nlobjSearchFilter = unsafeWindow.nlobjSearchFilter;
nlapiLookupField = unsafeWindow.nlapiLookupField;
nlapiLoadRecord = unsafeWindow.nlapiLoadRecord;
nlapiSubmitRecord = unsafeWindow.nlapiSubmitRecord;

GM_pageTransformations = {};

/**
 * The entrypoint for our userscript
 */
function GM_main(jQuery) {

    // We want to execute these on every NetSuite page
    GM_pageTransformations.header();
    GM_pageTransformations.browsertitle();

    // Here we build a function name from the path (page being accessed on the NetSuite domain)
    var path = location.pathname;
    if(path.indexOf('.')>-1) path = path.substr(0,path.indexOf('.'));
    path = toCamelCase(path,'/');

    // Now we check if a page "GM_pageTransformations" function exists with a matching name
    if(GM_pageTransformations[path]) {
        console.log('Executing GM_pageTransformations for '+path);
        GM_pageTransformations[path]();
    } else {
        console.log('No GM_pageTransformations for '+path);
    }
}

/**
 * Changes the header on all pages
 */
GM_pageTransformations['header'] = function() {
    // For example, lets make the header background red
    GM_addStyle('#ns_header, #ns_header * { background: red !important; }');
}

/**
 * Provides useful browser/tab titles for each NetSuite page
 */
GM_pageTransformations['browsertitle'] = function() {
    var title = jQuery('.uir-page-title-secondline').text().trim();
    var title2 = jQuery('.uir-page-title-firstline').text().trim();
    var title3 = jQuery('.ns-dashboard-detail-name').text().trim();
    if(title != '') {
        document.title = title+(title2 ? ': '+title2 : '')+(title3 ? ': '+title3 : '');
    } else if(title2 != '') {
        document.title = title2+(title3 ? ': '+title3 : '');
    } else if(title3 != '') {
        document.title = title3;
    }
}

/**
 * Changes app center card pages (dashboard pages)
 */
GM_pageTransformations['appCenterCard'] = function() {
    // For example, lets make add a new heading text on all Dashboard pages
    jQuery('#ns-dashboard-page').prepend('<h1>My New Dashboard Title</h1>');
}


/**
 * Convert a given string into camelCase, or CamelCase
 * @param {String} string - The input stirng
 * @param {String} delimter - The delimiter that seperates the words in the input string (default " ")
 * @param {Boolean} capitalizeFirstWord - Wheater or not to capitalize the first word (default false)
 */
function toCamelCase(string, delimiter, capitalizeFirstWord) {
    if(!delimiter) delimiter = ' ';
    var pieces = string.split(delimiter);
    string = '';
    for (var i=0; i<pieces.length; i++) {
        if(pieces[i].length == 0) continue;
        string += pieces[i].charAt(0).toUpperCase() + pieces[i].slice(1);
    }
    if(!capitalizeFirstWord) string= string.charAt(0).toLowerCase()+string.slice(1);
    return string;
}


// ===============
// CREDIT FOR JQUERY INCLUSION CODE: Brock Adams @ https://stackoverflow.com/a/12751531/4561907
/**
 * Check if we already have a local copy of jQuery, or if we need to fetch it from a 3rd-party server
 */
if (typeof GM_info !== "undefined") {
    console.log("Running with local copy of jQuery!");
    GM_main(jQuery);
}
else {
    console.log ("fetching jQuery from some 3rd-party server.");
    add_jQuery(GM_main, "1.9.0");
}
/**
 * Add the jQuery into our page for our userscript to use
 */
function add_jQuery(callbackFn, jqVersion) {
    var jqVersion   = jqVersion || "1.9.0";
    var D           = document;
    var targ        = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
    var scriptNode  = D.createElement ('script');
    scriptNode.src  = 'https://ajax.googleapis.com/ajax/libs/jquery/'
                    + jqVersion
                    + '/jquery.min.js'
                    ;
    scriptNode.addEventListener ("load", function () {
        var scriptNode          = D.createElement ("script");
        scriptNode.textContent  =
            'var gm_jQuery  = jQuery.noConflict (true);\n'
            + '(' + callbackFn.toString () + ')(gm_jQuery);'
        ;
        targ.appendChild (scriptNode);
    }, false);
    targ.appendChild (scriptNode);
}

您可以将该代码按原样复制并粘贴到一个新的Userscript中,它将执行以下操作。

  • 使浏览器标签页窗口具有有用的标题(显示订单号、客户名称、供应商名称等--不仅仅是 "销售订单")。
  • 将页眉背景改为红色(举个例子)
  • 在所有 "仪表盘 "页面的顶部添加一个新标题,写着 "我的新仪表盘标题"(举例说明)。
© www.soinside.com 2019 - 2024. All rights reserved.