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

时间:2019-02-22 17:43:58

标签: https netsuite

我正在尝试确保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
  };
});

1 个答案:

答案 0 :(得分:3)

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