How do I use requestSuitelet to call a suitelet fr...
# ask-stanley-ai
s
How do I use requestSuitelet to call a suitelet from Client Script without opening the Suitelet in a new window?
c
AI generated answer (using internal Slack threads):
To call a Suitelet from a Client Script without opening the Suitelet in a new window, you can use the
https
module's
get.promise
or
post.promise
methods. This allows you to make a GET or POST request to the Suitelet URL, and handle the response asynchronously. Here's a basic example of how you can do this:
Copy code
javascript
var suiteletURL = url.resolveScript({
    scriptId: 'customscript_my_suitelet',
    deploymentId: 'customdeploy_my_suitelet',
    returnExternalUrl: true
});

https.get.promise({
    url: suiteletURL
}).then(function(response){
    var responseBody = JSON.parse(response.body);
    // handle response here
}).catch(function onRejected(reason){
    log.error({
        title: 'GET failed',
        details: reason
    });
});
In this example,
customscript_my_suitelet
and
customdeploy_my_suitelet
should be replaced with your Suitelet's Script ID and Deployment ID, respectively. The
returnExternalUrl
parameter is set to
true
to get the external URL of the Suitelet. The
https.get.promise
method returns a Promise that resolves with the response from the Suitelet. You can then handle the response in the
then
method. If the GET request fails for any reason, the
catch
method will be called with the reason for the failure. Please note that this method will only work if your Suitelet is set to be Available Without Login. If it's not, you'll need to include the appropriate authentication in your request. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842108786
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835199058
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829367101
Please provide your feedback on this answer.