【问题标题】:How to add extra parameters with sendRedirect in SuiteScript 1.0?如何在 SuiteScript 1.0 中使用 sendRedirect 添加额外参数?
【发布时间】:2019-02-11 05:02:35
【问题描述】:

我是 SuiteScript 的新手,我似乎无法完全理解在重定向中添加 url 参数。我知道SuiteScript 1.0的文档说明可以根据这个函数添加额外的参数:

sendRedirect(类型、标识符、id、编辑模式、参数)

type {string} [required] - The base type for this resource

identifier {string} [required] - The primary id for this resource (record type ID for RECORD, scriptId for SUITELET, taskId for tasklink, url for EXTERNAL)

id {string} [optional] - The secondary id for this resource (record type ID for RECORD, deploymentId for SUITELET)

editmode {boolean true || false} [optional] - For RECORD calls, this determines whether to return a URL for the record in edit mode or view mode. If set to true, returns the URL to an existing record in edit mode, otherwise the record is returned in view mode.

parameters {hashtable} [optional] - An associative array of additional URL parameters as name/value pairs

但我真的对最后一个第四个参数感到困惑,文档指出需要关联数组。我已经尝试编写此代码来测试添加该参数。

function suitelet(request, response) {
    var arrayParam = [];
    arrayParam.push({custparam_key: 'value'});
    response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', 
    arrayParam);
}

但我无法找到最后一个参数在我的 Suitelet 中的位置。上面的代码确实允许用户使用其他默认参数重定向回相同的表单本身。但我不想要相同的默认参数。我希望能够在需要重定向用户的某些条件下制作额外的自定义参数。

我希望这一切都说得通。我觉得也许我不明白最后一个参数的用途。如果是这种情况,那么任何澄清都会有所帮助!

【问题讨论】:

  • 您是否尝试将简单的 JSON 对象作为参数传递给 sendRedirect(即键值对,例如:{ a: 'aa', b: 'bb' })?
  • 我有,但是在重定向表单后我无法捕获该参数。我猜也许它确实有效。也许我只是不知道该参数在 GET 和 POST 方法的上下文中的位置。

标签: javascript url redirect netsuite suitescript


【解决方案1】:

像这样创建你的关联数组:

 params['custparam_test1'] = value_test1;

然后得到这个:

var param = request.getParameter('custparam_test1')

在您的代码中,arrayParam[0] 中有一个对象,它是零位置,但它不是关联数组。

【讨论】:

    【解决方案2】:

    你的代码应该是:

    function suitelet(request, response) {
        var params = {
          custparam_key: 'value'
        };
        response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', params);
    }
    

    【讨论】:

      【解决方案3】:
      sendRedirect(type, identifier, id, editmode, parameters)
      

      但是你把它当作

      response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', 
      arrayParam);
      

      所以如果你把它与文档上的参数相匹配

      Type = Suitelet
      identifier = customscript_a
      id = customdeploy_a
      editmode = arrayParam
      

      你应该把它称为

      response.sendRedirect('SUITELET', 'customscript_a', 'customdeploy_a', null, arrayParam);
      

      【讨论】:

      • 好的,我刚试过这个,到目前为止,我似乎仍然无法在表单重定向后捕获那个额外的参数。为了提供上下文,每当用户点击 Suitelet 上的提交按钮时,我都会尝试将表单重定向回自身。重定向此表单后,我想从 sendRedirect() 中捕获添加的额外参数,以在我的代码中执行一些条件逻辑。我尝试过使用function suitelet(request, response) { var param = request.getParameter('custparam_key') } 但这没有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 2013-07-20
      • 2019-03-17
      • 2012-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多