首页 文章

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

提问于
浏览
0

我用suitelet构建了一个表单,它有一个子列表,下拉列表和一个按钮 . 在用户勾选子列表上的一些选项后,按下一个按钮,并通过其他地方的休息发送所选项目 .

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说是noobie)它对我来说似乎是一个问题解决者,因为它检索当前在客户端活动的记录 - 背景 . 它适用于下拉菜单,并且有一个方法getSublist(options),尽管它返回只有getColumn()方法的record.Sublist . 因此,它对我不起作用 . 那么,一旦按下按钮,有没有办法将子列表参数从套件中传递给customerscript?

1 回答

  • 2

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

    var currentRec = currentRecord.get();
    var numLines = objRecord.getLineCount({
        sublistId: 'item'
    });
    var sublistFieldValue = currentRec.getSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        line: 3
    });
    

    如果您真的想从Suitelet传递一些内容到客户端功能,您必须以这种方式设置按钮:

    var someTextToPassToTheClientscript = 'The Suitelet send its regards';
    form.addButton({
        id : 'custpage_some_button',
        label : 'MyButton',
        functionName : 'functionSendRequest("' + someTextToPassToTheClientscript + '")'
    });
    

    然后让你的客户端收到它:

    /*
     * @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
        }
    });
    

相关问题