Netsuite 在2.x API中将变量从suitelet传递到clientscript?

Netsuite 在2.x API中将变量从suitelet传递到clientscript?,netsuite,suitescript,Netsuite,Suitescript,我用suitelet构建了一个表单,它有一个子列表、下拉列表和一个按钮。在用户勾选子列表上的某些选项后,按下按钮,所选项目通过rest发送到其他位置 Suitelet: @NApiVersion 2.x *@NScriptType Suitelet */ define(['N/ui/serverWidget', 'N/search', 'N/https', 'N/record'], function(serverWidget, search, https, record) {

我用suitelet构建了一个表单,它有一个子列表、下拉列表和一个按钮。在用户勾选子列表上的某些选项后,按下按钮,所选项目通过rest发送到其他位置

Suitelet:

  @NApiVersion 2.x
  *@NScriptType Suitelet
  */
define(['N/ui/serverWidget', 'N/search', 'N/https', 'N/record'],
  function(serverWidget, search, https, record) {
    function onRequest(context) {
     if (context.request.method === 'GET') {
       var form = serverWidget.createForm({ ... });
       form.clientScriptModulePath = 'path/to/client/script';
       // code to build a sublist, add a button and write page
      } return {
         onRequest: onRequest
        };
      });
然后,我的客户端脚本类似于:

* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(
    [ 'N/currentRecord', 'N/https' ],
    function(currentRecord, https) {
      functionSendRequest(sublist //the sublist that I want to get from the suitelet)
      {
        //code to build json string and send http request
      } return {
         saveRecord: test
        }
    });

现在,在花了几个小时研究这个问题之后,我注意到了一个N/currentRecord(我对netsuite很熟悉),它似乎是一个解决问题的工具,因为它检索的是当前在客户端上下文中处于活动状态的记录。它对下拉菜单非常有用,有一个方法getSublist(options),不过它返回的record.Sublist只有getColumn()方法。因此,它对我来说真的不起作用。那么,有没有一种方法可以在按下按钮后将sublist参数从suitelet传递到clientscript?

要解决您的问题,您可以使用currentRecord中的getSublistValue,如下所示:

var currentRec = currentRecord.get();
var numLines = currentRec.getLineCount({
    sublistId: 'item'
});
var sublistFieldValue = currentRec.getSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    line: 3
});
/*
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(
    ['N/currentRecord', 'N/https'],
    function (currentRecord, https) {
    functionSendRequest(textReceivedFromSuitelet) {
        //code to build json string and send http request
    }
    return {
        functionSendRequest : functionSendRequest
    }
});
如果您真的想将某些内容从Suitelet传递到客户端功能,则必须按如下方式设置按钮:

var someTextToPassToTheClientscript = 'The Suitelet send its regards';
form.addButton({
    id : 'custpage_some_button',
    label : 'MyButton',
    functionName : 'functionSendRequest("' + someTextToPassToTheClientscript + '")'
});
然后让您的clientscript按如下方式接收:

var currentRec = currentRecord.get();
var numLines = currentRec.getLineCount({
    sublistId: 'item'
});
var sublistFieldValue = currentRec.getSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    line: 3
});
/*
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(
    ['N/currentRecord', 'N/https'],
    function (currentRecord, https) {
    functionSendRequest(textReceivedFromSuitelet) {
        //code to build json string and send http request
    }
    return {
        functionSendRequest : functionSendRequest
    }
});

要解决您的问题,您可以使用currentRecord中的getSublistValue,如下所示:

var currentRec = currentRecord.get();
var numLines = currentRec.getLineCount({
    sublistId: 'item'
});
var sublistFieldValue = currentRec.getSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    line: 3
});
/*
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(
    ['N/currentRecord', 'N/https'],
    function (currentRecord, https) {
    functionSendRequest(textReceivedFromSuitelet) {
        //code to build json string and send http request
    }
    return {
        functionSendRequest : functionSendRequest
    }
});
如果您真的想将某些内容从Suitelet传递到客户端功能,则必须按如下方式设置按钮:

var someTextToPassToTheClientscript = 'The Suitelet send its regards';
form.addButton({
    id : 'custpage_some_button',
    label : 'MyButton',
    functionName : 'functionSendRequest("' + someTextToPassToTheClientscript + '")'
});
然后让您的clientscript按如下方式接收:

var currentRec = currentRecord.get();
var numLines = currentRec.getLineCount({
    sublistId: 'item'
});
var sublistFieldValue = currentRec.getSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    line: 3
});
/*
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(
    ['N/currentRecord', 'N/https'],
    function (currentRecord, https) {
    functionSendRequest(textReceivedFromSuitelet) {
        //code to build json string and send http request
    }
    return {
        functionSendRequest : functionSendRequest
    }
});

嘿,非常感谢你的回复!谢谢你,我试试看。好奇的是,有没有办法用按钮上的functionName选项调用suitelet中的另一个函数?我无法让它工作,stackoverflow上的另一个人建议使用客户端脚本。但是,从客户端发送rest调用似乎不是一个好方法。通过POST将数据从clientscript传递到suitelet,使用POST正文中的一个变量标识操作类型,并让suitelet调用Restlet。嘿,非常感谢您的回复!谢谢你,我试试看。好奇的是,有没有办法用按钮上的functionName选项调用suitelet中的另一个函数?我无法让它工作,stackoverflow上的另一个人建议使用客户端脚本。但是,从客户端发送rest调用似乎不是一个好方法。通过POST将数据从clientscript传递到suitelet,使用POST正文中的一个变量标识操作类型,并让suitelet调用Restlet。