Why do I get error "ReferenceError: "Promise" is n...
# suitescript
t
Why do I get error "ReferenceError: "Promise" is not defined." Here's my code:
var gapiUrl = '<https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=>' + fromLat + ',' + fromLong + '&destinations=' + toLat + ',' + toLong + '&mode=fastest;car;traffic:enabled&key=XXXXXXX0&language=en-EN&sensor=false';
log.debug('gapiUrl', gapiUrl);
var headerObj = {
'Content-Type': 'application/json',
Accept: 'application/json',
'User-Agent-x': 'SuiteScript Call',
};
https.post.promise({
url: gapiUrl,
headers: headerObj,
body: {
origins: fromLat + ',' + fromLong,
destinations: toLat + ',' + toLong
}
})
.then(function(response) {
log.debug({
title: 'Response',
details: JSON.stringify(response)
});
if(response.rows[0].elements[0].status == 'OK')
{
log.debug('response', response.rows[0].elements[0].distance.text);
return response.rows[0].elements[0].distance.text;
}
}).catch(function onRejected(reason) {
log.debug({
title: 'Invalid Request: ',
details: reason
});
});
k
Your .then has a return in it. I'm assuming that is your problem. If you want to return something would specify a variable in global.
b
Suitescript 2.1 is the one with Promise support
t
2.1 resolves it but I still get this error "SSS_USAGE_LIMIT_EXCEEDED"
k
What script type?
t
Its a Suitelet @karlenigma
I am wondering if the header is correct.. I just copied it to other script that we have 😅
k
That error is usually when governance has gone over the limit.
t
yeah I know, so it means Netsuite can only communicate less than 100 request to an api?
k
Are you looping in the suitelet?
t
yes I am looping every coordinate from a search that I load
k
That could be the issue. I'm not sure but check the governor on the post call and work out how much you will use against the script limit.
t
Ok Karl, one quick question is there a way that I can only get the first 50 and the succeeding after 5 minutes to so that I cant reach the no of governance allowed?
k
In what context are you running this suitelet?
If you doing something this heavy I would have thought a mapreduce script would be more beneficial
t
We have a saved search interface like created in suitelet. And when user input miles on a field, system will get every vendor within the miles entered
k
I would have thought having a custom record with the info stored in the backend before would be more beneficial
Linked to the vendor.
Then your search is against a record and your not getting the distances every time.
t
That's probably my last resort. Design a custom record that will store vendor and its distance detail.
k
Tbh that would be my first port of call due to the governance and having the info stored.
t
yeah me too.. but i guess the previous developer does not anticipate datae redundancy and increasing of vendor records
Thank you @karlenigma
k
No worries. My route is always data up front. 😂