RE: How to call a Suitelet from a Portlet
I have a portlet script (2.0) in which I want to make a call to a Suitelet and receive a response.
I have tried setting up the call a lot of different ways, but it results in the same error: “The URL must be a fully qualified HTTP URL.”
In my portlet script, I set it up like this to make the call:
var suiteletUrl = url.resolveScript({
scriptId: ‘customscript_test_sl’,
deploymentId: ‘customdeploy_test_sl’,
returnExternalUrl: false
});
var response = http.post({
url: suiteletUrl,
body: testId
});
or just:
var response = http.get({
url: suiteletUrl
});
I have tried having return external URL = true, setting the suitelet to available without login (but I do not want that), I have tried using http.get, http.post, https.get and https.post. Nothing works.
Internal suitelet urls require that the requesting client have the JSESSIONID session cookie set to a valid value. Serverside scripts (essentially everything that isn’t client script) dont have access to the session cookie so your requests to the internal suitelet url should fail.
My advice is to take whatever code you want to share between your portlet and suiteletĀ and place it into a custom module that is shared by both scripts.
I tried custom module and it does what I need it to do. Thank you!
maza
So now with https module and using returnexternalurl = true, I do not get the error. However, as response I get an HTML text containing “You are not allowed to navigate directly to this page” and “Log In Again”.
dominicb
Use https, set external to false and add
suiteletUrlĀ = ‘https://YOURACCOUNTID.app.netsuite.com’ + suiteletUrl ;
before the https post. Fetch the base URL from a deployment parameter, or build it using the account ID from runtime if you’re concerned about the hardcoding.