我正在尝试确保NetSuite上的Salesorder上的任何更改都会反映在我的Saleserdore Collection copy cloud firestore数据库中。
由于某种原因,我在尝试编辑和保存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
};
});
服务器端HTTP调用是同步的,并返回响应而不是承诺。
如今,可以在服务器端套索中使用http.[get|post|etc].promise
。
任何人都可以猜测,如果您调用其中的几个,或者脚本是否会在没有承诺实现的情况下退出,但API确实可以按照套件2.1。
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/https'], function (https) {
function afterSubmit(context) {
https.post.promise({
url: "https://stackoverflow.com",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: "Hey planet"
})
});
}
return {
afterSubmit: afterSubmit
};
});
评论中的标签(@NApiVersion 2.1
)很重要,否则您使用的是Suitescript 2.0,它不支持较新的JavaScript功能。