else if (request.getMethod() == 'POST') { ...
# suitescript
h
else if (request.getMethod() == 'POST') { var custpage_name = request.getParameter('custpage_name'); var custpage_email = request.getParameter('custpage_email'); var custpage_phone = request.getParameter('custpage_phone'); var custpage_address = request.getParameter('custpage_address'); var custpage_question = request.getParameter('custpage_question'); if((custpage_name && custpage_email && custpage_phone && custpage_address && custpage_question !== " ") ) { var rec = nlapiCreateRecord('customrecord_contact_query'); rec.SetFieldValue('custrecord_name_contact_query', custpage_name); rec.SetFieldValue('custrecord_email_contact_query', custpage_email); rec.SetFieldValue('custrecord_phone_contact_query', custpage_phone); rec.SetFieldValue('custrecord_address_contact_query', custpage_address); rec.SetFieldValue('custrecord_question_contact_query', custpage_question); var id = nlapiSubmitRecord(rec); } else{ response.write("Error: Go Back and fill the Suitelet form."); } }
b
you will need to explain what your problem is
though its almost certainly that ugly if statement
😂 1
s
Yeah, it looks like the If statement has three separate clauses, all OR’ed together. However, there is repetition in each of them. In fact, the only difference between the three, is that you are checking whether
custpage_question
is not a single blank space, not NaN, or not undefined. The rest of each of those three if clauses is just checking if custpage_name, custpage_email, custpage_phone, or custpage_address have truthy values. Probably not what you actually intended.
b
you kinda missed how bad it is
if you factor it, its equivalent to
Copy code
custpage_name && custpage_email && custpage_phone && custpage_address && (custpage_question  !== " " || custpage_question  !== NaN || custpage_question !== undefined )
the expression within the parenthesis is equivalent to true
h
actually i wanted to create a custom record using suitelet form
s
you’re right, it can’;t be equal to three non-equal things, so it it always true
b
@Hardick Pandya your task sounds doable
your code for it looks mostly correct besides spelling setFieldValue wrong
s
@battk I noticed that. I was attempting to lead the OP there without exactly saying it. Was hoping they’d catch on on their own.
h
Its working, thanks. it was "setFieldValue" , not "SetFieldValue".
b
minor spoiler, you probably need more experience with javascript if that particular issue was a problem
s
Curious, what editor are you using? I wouldn’t normally recommend it, but for SS 1.0, Eclipse with the SuiteCloud IDE has all the code-completion you’ll ever need or want in it, and would have helped avoid the mis-spelling of the function name.
👍 1
h
sure Sir
s
and it’s free, so no investment required
s
that said, webstorm is a trivial investment
(relative to the cost of other tools, or say a NS license 🙂 )
s
If you have a secure NS job, WebStorm a no brainer. If this is training or preparation for an uncertain position, you might hold off on that investment. More importantly, good tools can help improve your code, but only to a point. you have to understand the language you are programming in, standard patterns and techniques, and more specifically for NetSuite, how the SuiteScript API’s and script types work. But, if you have access to a NetSuite environment, someone must be paying for it, as they no longer give out free Test Drive accounts (or at least, I thought Oracle put an end to that)
I think you can do a free one month trial of WebStorm, to see if it’s worth the money, too.
s
fortunately, webstorm is good for far more than just NetSuite development. I mean come on, webstorm costs less than a new video game. But if that's too much then there is VSCode which several people on here have described using alongside @hitc/netsuite-types
If I had to go 'free' I'd definitely pick VSCode over Eclipse.
h
i am using VSCode
👍 2
s
There’s a VS Code plug-in called SuiteSnippets to help with SuiteScript code completion, but I’m not sure if it supports SuiteScript 1.0, it only claims to support 2.0
s
I'd expect the old school NS api download would work for (code completion for) SS1, though I havent tried it in vscode.
s
I'd just not start at 1.0 when learning suitescript for the first time.
1000 1
s
Every so often I see people relatively new to SuiteScript and NetSuite (and maybe just new to development in general) asking about getting started with SuiteScript 1.0 I think there is a mistaken assumption that it is somehow easier or simpler than 2.0. I will admit that for the first 1-2 years the documentation on SuiteScript 2.0 was very lacking which made it hard to get started. That is no longer the case, though.
s
I still think the API itself for 1.0 is superior to 2.0
plain functions that take parameters vs every-function-must-take-an-object-except-somtimes
s
Well, yeah, object parameters could be regarded as good or bad. But, 1.0 will be forever stuck on the old Rhino engine, limited to ES5.1 support, which makes it decidedly inferior to SS 2.1 Though I suppose none of that really matters if you are transpiling from TypeScript down to ES5, and even less so if using NFT or other libraries instead of calling SuiteScript functions directly.
s
I do agree the other aspects of SS1 are a bummer, and glad to see 2.1 adopting all the way up to ES2019 so far!
my biggest complaint about the 'every function takes an object' is it prevents using any partial application/currying techniques to those apis.