Does anyone have an example of a custom promise wi...
# suitescript
m
Does anyone have an example of a custom promise within suitescript 2.0
b
Copy code
function createRecord(type) {
  return new Promise(function(resolve) {
    record.create.promise({type: type}).then(resolve);
  });
}

createRecord(record.Type.CUSTOMER).then(function(newRecord) {
  // Do more stuff
});
That's a super simple custom promise. It's equivalent to this:
Copy code
record.create.promise({type: record.Type.CUSTOMER}).then(function(newRecord) {
  // Do more stuff
});
m
that only works because record.create has a promise
I am trying to do this for a custom function
b
What is the custom function doing?
You can't just convert synchronous code into asynchronous.
m
yes I am understanding that now
custom function performs multiple searches returns a number, so in other words as mentioned in the other thread bellow, I have to rewrite the whole function to utilize promises on the searches themselves
👍 1
b
JavaScript is single threaded, so it can only work on one execution at a time.
s
it's not really accurate to say JavaScript is single threaded these days.