NetSuite SuiteScript,在 API 调用完成时阻止脚本触发
NetSuite SuiteScript, prevent script from firing when API call is done
我似乎无法搜索我的 question/problem。请指教
当我对 NetSuite 进行 API 调用(插入新记录或更新现有记录)时,SuiteScript 被触发并发回我的系统(预计会发帖,在 API 上触发调用不是)。
我找到了一种方法来限制脚本仅与 UI 操作交互:
if (scriptContext.type !== scriptContext.UserEventType.CREATE &&
scriptContext.type !== scriptContext.UserEventType.EDIT) {
return;
}
但是,当 API 调用完成时它仍然会触发。任何想法或任何人都可以指出我正确的方向吗?
完整脚本供参考:
*@NScriptType UserEventScript
*/
define(["N/record", "./cm/graphRequest", "./cm/hubRequest"],
function(record, graphRequest, hubRequest) {
function onSubmitProcessing(scriptContext) {
if (scriptContext.type !== scriptContext.UserEventType.CREATE &&
scriptContext.type !== scriptContext.UserEventType.EDIT) {
return;
}
var token = graphRequest.getToken();
var currentRecord = scriptContext.newRecord;
var vendorRecord = record.load({
type: record.Type.INVENTORY_ITEM,
id: currentRecord.id,
isDynamic: true
});
var payload = JSON.stringify(vendorRecord);
var sendObject = {
hubAccessToken: token.access_token,
body: payload,
method: "/api/Part/UpdateFromNetSuite",
url: "https://requestinspector.com/inspect/<<some value for testing>>"
};
var response = hubRequest.post(sendObject);
if (response.hubId !== undefined && response.hubId !== null) {
record.submitFields({
type: record.Type.INVENTORY_ITEM,
id: currentRecord.id,
values: {
custitem_inventoryitem_hub_id: response.hubId
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
}
return {
afterSubmit: onSubmitProcessing
};
});
提前致谢。
PS(编辑):正如下面答案中提到的,这是我成功错过的内容:
Customizations/Scripting/Script 部署/[所需脚本]/Edit/Context 过滤/
在那里,在“执行上下文”中 select 需要的项目。在我的例子中,它只是“用户界面”,需要 selected。保存,问题解决。
感谢 Jala 为我指明了正确的方向。
在脚本部署记录中,有一个上下文过滤选项卡,可让您设置脚本执行的上下文。
N/runtime 也有 runtime.executionContext 和 runtime.ContextType.
我似乎无法搜索我的 question/problem。请指教
当我对 NetSuite 进行 API 调用(插入新记录或更新现有记录)时,SuiteScript 被触发并发回我的系统(预计会发帖,在 API 上触发调用不是)。
我找到了一种方法来限制脚本仅与 UI 操作交互:
if (scriptContext.type !== scriptContext.UserEventType.CREATE &&
scriptContext.type !== scriptContext.UserEventType.EDIT) {
return;
}
但是,当 API 调用完成时它仍然会触发。任何想法或任何人都可以指出我正确的方向吗?
完整脚本供参考:
*@NScriptType UserEventScript
*/
define(["N/record", "./cm/graphRequest", "./cm/hubRequest"],
function(record, graphRequest, hubRequest) {
function onSubmitProcessing(scriptContext) {
if (scriptContext.type !== scriptContext.UserEventType.CREATE &&
scriptContext.type !== scriptContext.UserEventType.EDIT) {
return;
}
var token = graphRequest.getToken();
var currentRecord = scriptContext.newRecord;
var vendorRecord = record.load({
type: record.Type.INVENTORY_ITEM,
id: currentRecord.id,
isDynamic: true
});
var payload = JSON.stringify(vendorRecord);
var sendObject = {
hubAccessToken: token.access_token,
body: payload,
method: "/api/Part/UpdateFromNetSuite",
url: "https://requestinspector.com/inspect/<<some value for testing>>"
};
var response = hubRequest.post(sendObject);
if (response.hubId !== undefined && response.hubId !== null) {
record.submitFields({
type: record.Type.INVENTORY_ITEM,
id: currentRecord.id,
values: {
custitem_inventoryitem_hub_id: response.hubId
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
}
return {
afterSubmit: onSubmitProcessing
};
});
提前致谢。
PS(编辑):正如下面答案中提到的,这是我成功错过的内容:
Customizations/Scripting/Script 部署/[所需脚本]/Edit/Context 过滤/
在那里,在“执行上下文”中 select 需要的项目。在我的例子中,它只是“用户界面”,需要 selected。保存,问题解决。 感谢 Jala 为我指明了正确的方向。
在脚本部署记录中,有一个上下文过滤选项卡,可让您设置脚本执行的上下文。
N/runtime 也有 runtime.executionContext 和 runtime.ContextType.