0

我有一个 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

知道我怎么能做到这一点吗?一个代码片段会很有帮助。

4

1 回答 1

0

在推荐的场景中,如果您需要每个订单一个,您可以创建一个交易主体字段并在将商品添加到购物车时从前端填充该字段。

如果您需要逐个项目的推荐代码,您必须创建一个交易项目选项并手动将 URL 中的“值”添加到该字段中。

如果您要读取 URL 参数并将其保存到 NetSuite Backend 字段中,请使用XSS Injection超级小心,转义任何值并在保存之前确认该值是正确的。

于 2019-04-28T14:33:52.880 回答