当尝试使用https模块命中端点时,“未定义承诺”

问题描述 投票:0回答:1

我正在尝试确保Netsuite上salesOrder的任何更改都反映在Cloud Firestore数据库中的salesOrder集合副本上。

出于某种原因,我在尝试编辑和保存salesOrder时得到的响应是这个org.mozilla.javascript.EcmaError: ReferenceError: "Promise" is not defined. (/SuiteScripts/postSalesOrder-v2.js#30)

这是链接到salesOrder的脚本:

/**
 * User Event 2.0 example detailing usage of the Submit events
 *
  @NApiVersion 2.x
  @NModuleScope SameAccount
  @NScriptType UserEventScript
  @appliedtorecord salesorder
 */

define(['N/https'], function(https) {
  function myAfterSubmit(context) {
    var apiURL = 'https://myApiEndpoint';
    var headers = {
      'content-type': 'application/json',
      accept: 'application/json'
    };

    https.post
      .promise({
        url: apiURL,
        headers: headers,
        body: JSON.stringify(context.newRecord)
      })
      .then(function(response) {
        log.debug({
          title: 'Response',
          details: response
        });
      })
      .catch(function onRejected(reason) {
        log.debug({
          title: 'Invalid Post Request: ',
          details: reason
        });
      });
    return true;
  }

  return {
    afterSubmit: myAfterSubmit
  };
});
https netsuite
1个回答
3
投票

服务器端http调用是同步的并返回响应而不是Promise。

© www.soinside.com 2019 - 2024. All rights reserved.