RE: How to call a Suitelet from a Portlet

Answered

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.

mzander Rookie Asked on June 22, 2020 in SuiteScript.

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”.

on June 22, 2020.

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.

 

on June 22, 2020.
Add Comment
1 Answers
Best answer

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.

Intermediate Answered on June 22, 2020.

I tried custom module and it does what I need it to do. Thank you!

on June 23, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.