How to make HTTPS request asynchronous in usereven...
# ask-stanley-ai
j
How to make HTTPS request asynchronous in userevent script?
c
AI generated answer (using internal Slack threads):
To make an HTTPS request asynchronous in a UserEvent script, you can use the
https.post.promise(options)
method. However, it's important to note that server-side promises in SuiteScript run synchronously, meaning each individual script will wait for all processing to complete before continuing. Here is a sample code snippet for making an asynchronous HTTPS request:
Copy code
javascript
var myHeaders = {
    'Content-Type': 'application/json'
};

var myPayload = {
    "recordType": "customer",
    "id": "123"
};

https.post.promise({
    url: '<https://my-endpoint-url>',
    headers: myHeaders,
    body: myPayload
})
.then(function(response){
    log.debug({
        title: 'Response',
        details: response.body
    });
})
.catch(function onRejected(reason){
    log.debug({
        title: 'Rejected Promise',
        details: reason
    });
});
In this example, the
https.post.promise(options)
method returns a promise that is fulfilled with the HTTP response. The
then
method is used to specify what to do when the promise is fulfilled, and the
catch
method is used to specify what to do if the promise is rejected. ****** 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.798965514
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.7939291
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.793850899
Please provide your feedback on this answer.