What Do I Want To Happen
I want to be able to call a Suitelet from a User Event passing in a record id.
What Currently Happens
Either a "INSUFFICIENT_PERMISSION" error is thrown or no error is thrown but the suitelet is not called.
The Details
Hey all, I'm trying to call a suitelet from a User Event. We have a record getting created with some data, upon creating that record in the user event I want to create a Customer and Sales Order. I also need the User Events of those records to fire off. I know a user event cannot trigger another user event so I have written a suitelet to call which will do the processing. I am trying to call the suitelet with the following code.
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
});
Using this code, no errors are thrown, but the Suitelet is also not triggered. I know this because as soon as my suitelet triggers I log "Running"
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));
Now I am logging the URL that the User Event is using and if I copy and paste that into the browser, the suitelet runs. So I know the URL is correct.
WHAT HAVE I TRIED
I have tried adding the
returnExternalUrl: true
parameter of the https call. Using this DOES call the Suitelet however I can an error stating
"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}
The Suite Deployment is set to "Available Without Login : true" and "All Roles : true"
Update
I am getting You must login before accessing this page.
I am logged in and calling it from a UserEvent