When working with ranges for a query, you may have used the SysQuery class already.
With some of the methods in this blog post you can live without, but they sure can make your life as a programmer a bit easier.
Some examples. We gonna use a querybuildrange, setting it like this:
Now we set the actual value for the range, by using this format:
This method takes a string as argument.
But if you are not sure which type your argument is gonna be, you might wanna do a conversion to be on the safe side. It doesn't hurt to make a habit of writing your code like this:
Hey and what about that other method from the Global class, QueryValue? No use of that?
Maybe you are used to writing something like this:
This converts the argument (anytype) to a string as well. Actually, this is equally good, as this method calls SysQuery::Value().
If we wanna list all the customers that do NOT have the currency EUR set up, we can do something like this:
The SysQuery class comes to the rescue here as well, by providing the exact same functionality
Check it out, this method converts the argument to a string AND adds an exclamation point in front of it.
No range value
If you range has been set up, but you don't want to apply anything yet, you can provide an empty string as argument. This way the query will retrieve all records.
Again, SysQuery has something in its toolbox for us as well:
Coming from the documentation in the code:
Used when you want to have a completely open range, no limitations; "a blank range"
use this method for future compability
Don't mix this one up with the method valueEmptyString. The method valueEmptyString will retrieve records with no value for the specific field.
And this one of course has an opposite, valueNotEmptyString
This will retrieve records where there is a value set up, so no null values.
To end this post, maybe the method that saves you from writing code the most: Range.
We can set ranges from/to with SysQuery class as well.
The method will add the dots ('..') when appropriate, so something like this:
Like stated at the intro of this post: Nothing lifesaving, but nice-to-haves.