Hey folks, just a question. Netsuite won't allow ...
# suitescript
m
Hey folks, just a question. Netsuite won't allow me to write the words
async function(){   console.log('hi')   }
in a JS file (it's not attached to a script record of any sort). Is there any way to get around this? When I try to do this, it pops up with an error saying 'Syntax error: missing ; before statement'.
j
can you post the rest of your code?
m
Copy code
require(['N/record', 'N/search'], function(record, search)
        {
            (async function() {

                var s = await search.create.promise({
                    type: 'transaction',
                    filters: [
                        {name: 'internalid', operator: 'anyof', values:[nlapiGetRecordId()]}
                    ],
                    columns: [
                        {name: 'createdfrom'},
                        {name: 'shipdate', join: 'createdfrom'},
                        {name: 'item'},
                        {name: 'displayname', join: 'item'},
                        {name: 'custitem_cal_type', join: 'item'}
                    ]
                });
                var p = await s.runPaged.promise({pageSize:1000})

                var createdfrom = '';
                var duedate = '';
                var items = {};

                for(page_index = 0; page_index < p.pageRanges.length; page_index++)
                {
                    var pageRange = p.pageRanges[page_index];
                    var page = await p.fetch.promise(pageRange);
                    page.data.forEach(function(result)
                    {
                        if(createdfrom == '')
                        {
                            createdfrom = result.getText({name:'createdfrom'});
                        }
                        if(duedate == '')
                        {
                            duedate = result.getValue({name:'shipdate',join:'createdfrom'});
                        }
                        var item_id = result.getValue({name:'item'});
                        items[item_id] = {
                            classification: result.getText({name: 'custitem_cal_type', join:'item'}),
                            displayname: result.getValue({name: 'displayname', join:'item'})
                        }
                    })
                }

                console.log(items);


            }).then(function(){}).catch(console.log);
        })
    }
As you can tell, it's a bit of a mix between SS1 and SS2 with the nlapiGetRecordId(). It's going to be a form script ultimately (reacting when someone clicks a button). But this means it's just basically like sticking a script tag on the record... so I can't see why it's refusing to be async.
a
idk if you've modified that to share it but it looks like the extra closing brace is just a syntax error
m
Hmmm... well... I've tried something a lot more simple too... something like the following:
Copy code
require(['N/record', 'N/search'], function(record, search)
        {
            async function tests(){}
        })
Still fails
a
oh I thought it was erroring when you try to upload to file cabinet, but it isn't that, its erroring at runtime?
if its not attached to a script record how is it being loaded?
you have a beforeload UE and you're setting it as the client script module path on the context form?
if you are doing the above then you ALSO need a standard client script entry point even though you're not using a client script record.
Copy code
function pageInit(){}
...
async function ()
...
return { pageInit };
might work
I have to ask why not just do this as a 2.1 client script with define instead of require?
m
@Anthony OConnor It is erroring when I'm uploading to Netsuite, yeah. And yes, I have a beffore load UE and am settting it as the clietn script module path. It's inside a function that is called when a button is pressed.
I could do it as a 2.1 script, yes, just haven't experimented with that yet since I'm so used to attaching it in the 1.0 method. Hopefully will change here sometime though.
a
i had no problem uploading your file into the suitescript folder, I thought it only does that kind of validation if you upload it via the suitescript upload process when you're going through the create new script record process?
m
If you are using SuiteCloud Development framework check your
suitecloud.config.js
it may be running pre-deploy linting.