Hi all, I am trying to make the `Promise` work in ...
# suitescript
v
Hi all, I am trying to make the
Promise
work in my RESTlet code. but it just does not work and I am not sure what i am missing. I made the script that has a basic promise but then and catch clauses are ignored… I wonder if the RESTlet is return the result without waiting for
Promise
to either resolve or reject
Copy code
const savedSearch = search.load({id: savedSearchId});
savedSearch.run().each.promise(function (result) {
    log.debug("Promise clause");
    var name = result.getValue({name: 'name'});
    log.debug("name", name)
    return true
})
    .then(res => {
        log.debug("complete", res)
    })
    .catch(err => {
        log.debug("fail", err)
    })
This is what I got from Netsuite docs.
in the log, I can see log.debug(“Promise clause”); and log.debug(“name”, name). but other logs are not printed, meaning execution is skipping both clauses. May I know what I am missing?
b
looks okay
use
log.audit("complete", res)
and
log.error("fail", err)
to more easily find your logs using the type filters of the execution logs
1
v
Thank you for commenting again Yes, I initially wanted to use for
pagedData.fetch.promise()
but also it did not work. it does not throw an error. it does not log anything
Thanks I will try that now
b
the each promise is not very useful, you were better off with the fetch
v
yes, it just did not work with fetch. then I just used each as netsuite docs was using it as an example…
@battk Thank you, As you suggested, it worked after using
log.audit
not sure why debug does not work.
b
it always worked, you just never noticed the log since it doesnt log when you expect it to
👀 1
1
you can probably sort your logs by title and find all the ones you missed