我想发生什么
我希望能够通过传递记录ID的用户事件来调用Suitelet。
目前正在发生什么
要么抛出“ INSUFFICIENT_PERMISSION”错误,要么不抛出错误,但未调用套件。
详细信息
大家好,我正在尝试通过用户事件调用小套房。在用户要创建客户和销售订单的用户事件中创建记录时,我们会使用一些数据来创建记录。我还需要触发这些记录的用户事件。我知道一个用户事件无法触发另一个用户事件,因此我编写了一个套件来调用以进行处理。我正在尝试使用以下代码调用套件。
var scheme = 'https://';
var host = url.resolveDomain({
hostType: url.HostType.APPLICATION
});
var suitletURL = url.resolveScript({
scriptId : 'customscript_pws_sl_data',
deploymentId : 'customdeploy_pws_sl_data'
});
var parameters = {
dataid : scriptContext.newRecord.id,
};
log.debug("URL", scheme + host + suitletURL);
var response = https.post({
url : scheme + host + suitletURL + "&dataid=" + scriptContext.newRecord.id,
body : parameters
});
使用此代码,不会引发任何错误,但是Suitelet也不会触发。我知道这一点,因为一旦套件触发,我就会登录“正在运行”
log.debug("Running");
var user = runtime.getCurrentUser();
var script = runtime.getCurrentScript();
// Get parameters
var params = context.request.parameters;
log.debug("Context", JSON.stringify(context.request));
log.debug("Params", JSON.stringify(params));
现在,我正在记录用户事件正在使用的URL,如果将其复制并粘贴到浏览器中,则套件将运行。因此,我知道该网址是正确的。
我尝试了什么
我已经尝试添加
returnExternalUrl: true
https调用的参数。使用此DOES调用Suitelet,但我可以指出一个错误
"type":"error.SuiteScriptError","name":"INSUFFICIENT_PERMISSION","message":"Permission Violation: You need the 'Lists -> Items' permission to access this page. Please contact your account administrator.","stack":["createError(N/error)","getOrderLines(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_lib_ecommerce.js:972)","processData(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_lib_ecommerce.js:109)","onRequest(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_sl_ecommdata.js:40)"],"cause":{"type":"internal error","code":"INSUFFICIENT_PERMISSION","details":"Permission Violation: You need the 'Lists -> Items' permission to access this page. Please contact your account administrator.","userEvent":null,"stackTrace":["createError(N/error)","getOrderLines(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_lib_ecommerce.js:972)","processData(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_lib_ecommerce.js:109)","onRequest(/SuiteScripts/PWS Additional Modules/Additional Modules/Ecommerce Data/pws_sl_ecommdata.js:40)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
套件部署设置为“无登录可用:true”和“所有角色:true”
更新
I am getting You must login before accessing this page.
我已登录并从UserEvent调用它
将用户事件和Suitelet都设置为在管理员模式下运行,并使用“ returnExternalUrl:true”设置解决了此问题:)
var suitletURL = url.resolveScript({
scriptId : 'customscript_pws_sl_data',
deploymentId : 'customdeploy_pws_sl_data',
returnExternalUrl : true
});