When creating a SuiteQL query in SuiteScript I’m finding my query starts with the following structure:
|
|
What I’m finding with my SuiteQL queries is that I want to place all my inputs
up at the top.
I have found using the string interpolation character ?
dotted throughout my query both annoying to locate, and difficult to craft when creating the array of strings as the parameter. Once you have more than 3 parameters it gets quite painful to manage and you’ll need to create a function to help identify what parameters are needed for your query.
By defining all the query strings up the top it helps to read the parameter documentation (as it’s just above it) and to then reference throughout the rest of your queries.
Handling optional parameters
If you have optional parameters then you need to be careful of your operations on those NULL
parameter values.
You should check if the parameter IS NULL
before doing much with the parameter value.
For example, some queries may want to specifically operate on a date or a specific department or subsidiary. As these inputs are optional I need to design my queries to compensate for NULL
values. Therefore, you’ll see my query contain in their WHERE
clauses something like this:
|
|
So far this type of structure, while more verbose, has helped to show better structure with my SuiteQL queries. It’s like I’m using OOP principles when writing my queries!
This structure may certainly change in the future, but it’s what has helped me to date.