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.
m
@Anthony OConnor Sorry about the late reply. I'm technically uploading it via a Suitelet. It is overwriting a file that has been selected as a script. It's the validation that's causing a problem in this case šŸ˜›
a
so then
(it's not attached to a script record of any sort).
wasn't true?
if its replacing a file that IS attached to a script then it IS attached to a script, and that validation will run, so you'll have to make the syntax NS compliant
m
@Anthony OConnor Hold on... wait... let me check, I think I just had a brain fumble.
Okay, no, I was correct the first time. It's not attached to a script record at all.
(But it is a .js file... which is somehow triggering it... huh...)
I'm gonna play around with it some more. Thanks for your help on this šŸ™‚
@Marvin Thanks, but not using SCDF at all in this case. Just uploading a file to the cabinet via Suitescript.
a
I don't think I've ever used a script to upload a file into the file cabinet, so I'm not sure if that would default to triggering the script validation based on the .js file extension - it doesn't seem like it should because UI uploads of .js file don't trigger it. that said that IS what it appears to be doing, so maybe just make it NS syntax compliant and test it? it shouldn't be that difficult right? just add jsDoc header boiler plate and replace the one 1.0 SS nlapi call with the 2.0 equivalent
oh wait a second - is it possible the missing
;
syntax error its reporting is actually a problem with this upload suitelet, not the client script js file payload?
m
@Anthony OConnor I'll try out the JSDoc. Might be later today or tomorrow though... things are crazy busy here. Could be an issue with the Suitelet too... I didn't write it, it's part of a VSCode Extension. But I'm guessing it's more likely the script validation. In any case, I'll get back to you on what happens.
šŸ‘ 1
Thanks for your help btw šŸ™‚
šŸ‘ 1
@Anthony OConnor Looks like you are right. It no longer complains on upload about any
async
code when I add some JSDoc. Now gotta see if I can get it to function as a form button appropriately šŸ™‚
a
process for this is usually • a before load UE on the record in question • get the form object from the scriptContext and do a form.addButton • use the function name reference and any params you need in the functionName attribute • add a clientScriptModulePath to reference your .js script location