So you can actually create a promise serverside in...
# suitescript
m
So you can actually create a promise serverside in netsuite now. The question is what happens if i execute some long process in a promise and the script execution finishes, will my promise keep executing or does netsuite actually wipe out your process
s
very interesting - can you provide evidence of where a promise is supported in server-side script?
I mean, code that doesn't error and or documentation to support that?
I thought promises were strictly client-side in SuiteScript.
m
I think you can use a promise now with ss2.1 but i dont think itll execute once your script finishes executing
Im working on script to show u
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType Suitelet
 */
define(['N/record',
], function (record) {

    function onRequest(context) {
     
        const promise = new Promise(function (resolve, reject) {

            resolve(record.submitFields({ type: 'employee', id: 1681967, values: { title: 'Chief Of Happiness' } }))
            
        })
        promise.then(function (value) { 
            context.response.write('Record id ' + value + ' updated')
        })

    }

    return {
        onRequest: onRequest
    }
});
Replace the employee id with your id and it should update your title to "Chief Of Happiness"
s
I wonder if that's a '2.1 is beta' mistake on their part?
Do your
promise.then
ever get executed? and equally importantly, if you add a log or response after your
const promise
is it executed immediately (i.e. before your then())
In general I've found no need for promises server-side because the invocation of the script is a clean single thread of execution in an otherwise highly parallel application. i.e. NetSuite is doing massive multithreading and/or async stuff behind the scenes while also presenting the developer with a clean single threaded execution model.
b
you can make Promises, but NetSuite exposes nothing that is async, so you can't do anything interesting with the Promise
s
so you're saying netsuite is making promises it can't keep?
🤭 1