【发布时间】:2019-01-11 06:01:08
【问题描述】:
我有一个 Suitecommerce 网站产品页面,其中某些信息以查询参数的形式附加到 url。例如:https://my-ecommerce.com/product/someProduct?referralId=someValue
我的目标是在购买产品时将salesOrder 记录传递给某些外部 API 端点。我通过如下部署用户事件脚本来实现这一点:
function afterSubmit(type) {
// Url of the external api endpoint to push data
var url = "http://external-url/endpoint/";
// Get the new created record. It returns a nlRecordObj
var record = nlapiGetNewRecord();
// Get the record Id of that created record
var recordId = record.getId();
// Get the record of corresponding record Id and record type
var nlobj = nlapiLoadRecord("salesOrder",recordId);
// To log our request data
nlapiLogExecution("DEBUG","Test",JSON.stringify(nlobj));
// Set Headers for HTTP request
var headers = {"Content-Type":"application/json"};
// Performing HTTP request to our url with our newly created data as payload
var response = nlapiRequestURL(url, JSON.stringify(nlobj), headers);
}
但我还想传递的是 referralId 以及来自 suitecommerce url 的 salesOrder 记录。
我想到的一个解决方案是将url参数放在浏览器的本地存储中,然后从suitescript中获取它。但 Suite 脚本无法识别 window.localStorage。
知道我该如何做到这一点吗?代码 sn-p 会很有帮助。
【问题讨论】:
-
window对象不可用于服务器端脚本,例如 NetSuite 用户事件脚本。您必须在网页上嵌入脚本以获取referralId参数并使用它调用套件,或者将其添加到销售订单中的自定义字段,然后您可以从用户事件中引用该字段。至少这是一个建议……希望对您有所帮助。
标签: netsuite suitescript suitecommerce