首页 > 其他分享 >NetSuite 开发日记:如何管理多环境自定义列表值

NetSuite 开发日记:如何管理多环境自定义列表值

时间:2023-12-14 10:57:37浏览次数:26  
标签:const 自定义 NetSuite js 列表 123456 ID

在 NetSuite 中可以创建自定义列表,列表可用于为其他(自定义)记录上的下拉选项列表值。

var rec = record.create({
    type: 'customrecord_xx'
});

rec.setValue({
    fieldId: 'custrecord_xx_fld',
    value: '1' 
});
 
rec.save();

我们设置自定义列表值,需要使用该值的内部 ID。但是,内部 ID 是特定于环境的。这意味着,对于相同的自定义列表值,生产中的内部 ID 可能与沙盒中的内部 ID 不同。
image

那么,我们如何管理多个环境中同一自定义列表的内部 ID 不同的情况呢?

方式一:使用SuiteScript查询(N/search模块、N/query模块)
前提设置:

  1. 启用在子列表上显示 ID 字段
    image
  2. 为每个自定义列表值分配唯一且有意义的脚本 ID
    image
function getListValueId(list, listValueScriptId) {
    var listValueId = null;
     
    search.create({
        type: list,
        columns: [
            'internalid',
            'scriptid'
        ]
    }).run().each(function(result) {
        // Note: From tests, the script ID from the search results are always uppercase.
        if (result.getValue("scriptid") === listValueScriptId.toUpperCase()) {
            listValueId = result.getValue('internalid');
        }
        // Stop iterating when we find the target ID.
        return (listValueId === null);
    });
  
    return listValueId;
}
function getListValueId(listType, listValueScriptId) {
    var listValueId;
    
    const sql = "SELECT ID FROM ? WHERE scriptid = ?";
    var resultSet = query.runSuiteQL({ query: sql, params: [listType, listValueScriptId.toUpperCase()] }).asMappedResults();
 
    return listValueId = (resultSet.length === 1 ? resultSet[0].id : null);
}

但这种方式有个显而易见的缺点,查询需要消耗Usage(Usage是NetSuite管理API的一种方式)

方式二:将自定义列表值配置在javaScript文件

SuiteScript
    └─ src
        ├─ constant
        │      ├─ 123456
        │      │     └─ const.js
        │      ├─ 123456_SB1
        │      │     └─ const.js
        │      └─ const.js
        └─ suitelet
              └─ test_sl.js

SuiteScript/src/constant/123456/const.jsSuiteScript/src/constant/123456_SB1/const.js文件内容

// 123456/const.js
define([], function () {
  return {
    TASK_LEVEL: {
      LOW: 1,
      Medium: 2,
      High: 3
    }
  };
});

// 123456_SB1/const.js
define([], function () {
  return {
    TASK_LEVEL: {
      LOW: 4,
      Medium: 5,
      High: 6
    }
  };
});

SuiteScript/src/constant/const.js文件内容

/**
 * @NApiVersion 2.x
 */
define(['N/runtime', './123456/const', './123456_SB1/const'], function (runtime, prodConst, sandboxConst) {
	var constJSON = {};
	var accountId = runtime.accountId;
	switch (accountId) {
		case '123456':
			// 生产环境
			constJSON = prodConst;
			break;
		case '123456_SB1':
			// 沙盒环境
			constJSON = sandboxConst;
			break;
	}
	return constJSON;
});

SuiteScript/src/client/test_cs.js文件内容

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 * @NModuleScope SameAccount
 */
define(['../constant/const'], function (cuxConst) {
  /**
   * Definition of the Suitelet script trigger point.
   * @param {Object} context
   * @param {ServerRequest} context.request - Encapsulation of the incoming request
   * @param {ServerResponse} context.response - Encapsulation of the Suitelet response
   * @Since 2015.2
   */
  function onRequest(context) {
    var response = context.response;
    response.wirte(cuxConst.TASK_LEVEL.LOW);
  }

  return {
    onRequest: onRequest
  };
});

标签:const,自定义,NetSuite,js,列表,123456,ID
From: https://www.cnblogs.com/zhangchenyi/p/_ns_customlist.html

相关文章

  • java 两个列表的求交集、差集和并集
    java两个列表的求交集、差集和并集importjava.util.HashSet;importjava.util.List;importjava.util.Set;publicclassSetOperations{publicstaticvoidmain(String[]args){//创建两个列表List<String>list1=Arrays.asList(......
  • MUI增加自定义icon图标
    mui框架遵循极简原则,在icon图标集上也是如此,mui仅集成了原生系统中最常用的图标;使用icon图标集的优点:多个图标字体合成一个字体文件,避免每张图片都需要联网请求;字体可任意缩放,而图片放大会失真、缩小则浪费像素;可通过css任意改变颜色、设置阴影及透明效果;一、操作方法:(1)找到任意矢量......
  • 进行折线图tooltip自定义悬浮框展示,时间是横坐标
         ......
  • 兼容性复制功能/自定义mock数据/通用hook
    *****自定义mockconstresourceList=computed(()=>Array.from({length:20},(_,index)=>index).map((v,i)=>{return{id:i,joinList:Array.from({length:i},(_,index1)=>index1).map((v,......
  • jquery.validate 如何自定义验证规则
    $.validator.addMethod("isPassword",function(value,element){varreg=/^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{6,20}$/;returnreg.test(value);},"密码中必须包含含数字、字母、特殊符号");   $('#for......
  • 自定义单选框
    意义:Android使用RadioGroup内只能用RadioButton,不满足需求中的单选布局要求。步骤:使用CheckBox,结合checkSign和默认全部否定设置,判断checkSign来设置那个checkBox为true来实现效果。 privatevoidupdateChoseBox(){cboxDes.setChecked(false);c......
  • el-descriptions 描述列表 label 背景色失效问题
    <el-descriptionstitle="自定义样式列表":column="3"border><el-descriptions-itemlabel="用户名"label-class-name="my-label"content-class-name="my-content">kooriookami</el-descriptions-item>&......
  • 纯CSS实现可自定义间距虚线边框
    <!DOCTYPEhtml><html><head><metacharset="utf-8"><title></title><style>.border-wrapper{position:relative;margin:100pxau......
  • python 报错应对列表
    =========================RESTART:D:/Python37/ziti1.py========================Traceback(mostrecentcalllast):File"D:/Python37/ziti1.py",line1,in<module>importdocxModuleNotFoundError:Nomodulenamed'docx'>>......
  • Windows下获取设备管理器列表信息-setupAPI
    背景及问题:在与硬件打交道时,经常需要知道当前设备连接的硬件信息,以便连接正确的硬件,比如串口通讯查询连接的硬件及端口,一般手工的方式就是去设备管理器查看相应的信息,应用程序如何读取这一部分信息呢,Windows下的SetupAPI系列就可以解决这个问题示例程序#include<Windows.h>#......