LeaderBoard

How to use some of the lesser known methods of the SysQuery class

 imparted from here

 

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:

QueryBuildRange myQBR;
myQBR=this.query().dataSourceName('CustTable').addRange(fieldnum(CustTable,Currency));

Now we set the actual value for the range, by using this format:

myQBR.value('SetValue');

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:

myQBR.value(SysQuery::value('EUR'));

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:

myQBR.value(queryValue('EUR'));

This converts the argument (anytype) to a string as well. Actually, this is equally good, as this method calls SysQuery::Value().


Logical NOT

If we wanna list all the customers that do NOT have the currency EUR set up, we can do something like this:

myQBR.value('!EUR');

The SysQuery class comes to the rescue here as well, by providing the exact same functionality

myQBR.value(SysQuery::valueNot('EUR'));

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.

myQBR.value('');

Again, SysQuery has something in its toolbox for us as well:

myQBR.value(SysQuery::valueUnlimited());

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 methodvalueEmptyString will retrieve records with no value for the specific field.

myQBR.value(SysQuery::valueEmptyString());

And this one of course has an opposite, valueNotEmptyString

myQBR.value(SysQuery::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.

myQBR.value(SysQuery::range('EUR','USD');

The method will add the dots ('..') when appropriate, so something like this:

myQBR.value('EUR..USD');

Like stated at the intro of this post: Nothing lifesaving, but nice-to-haves

str2Datetime Function

str2Datetime Function:

Generates a utcdatetime value from the specified string of date and time information.
utcdatetime str2datetime( str text, int sequence ) 
















ParameterDescription

text

The string to convert into a utcdatetime value.

sequence

A three digit number that describes the sequence of the date components in the text parameter.





A utcdatetime value that represents the specified date and time.

If the value of the sequence parameter is invalid (such as -1, or 3, or 9876), the regional settings are used to interpret the text parameter.

If the input parameters describe an invalid date/time, then an empty string is returned.





The syntax requirements for the date portion of the text parameter are flexible. The variety of valid formats is the same as in the date2str function.

Each of the following calls to str2datetime is valid and produce the same output:







utc3 = str2datetime( "1985/02/25 23:04:59" ,321 ); utc3 = str2datetime( "Feb-1985-25 11:04:59 pm" ,231 ); utc3 = str2datetime( "2 25 1985 11:04:59 pm" ,123 ); 

Each component of the date time is represented by a digit in the sequence parameter:


  • 1 – day
  • 2 – month
  • 3 – year

For example, YMD is 321. All valid values contain each of these three digits exactly one time. If the value of the sequence parameter is invalid, the regional settings are used to interpret the input text parameter.

If the input parameters describe an invalid date and time, an empty string is returned.











static void JobTestStr2datetime( Args _args ) {     utcdatetime utc3;     str sTemp;     ;     utc3 = str2datetime( "1985/02/25 23:04:59" ,321 );     sTemp = datetime2str( utc3 );     print( "sTemp == " + sTemp );     pause; }

Axapta Dialog Validation - Stack Overflow

Axapta Dialog Validation - Stack Overflow:

Here is an example in AX 2009 of how to build a simple dialog using the RunBase class. In it I create a class called DialogExample and derive from RunBase. To show the dialog you simply need to run the class, but typically this would be done by pointing a MenuItem at the class.

public class DialogExample extends RunBase {     DialogField dialogName;     Name name;      #DEFINE.CurrentVersion(1)     #LOCALMACRO.CurrentList         name     #ENDMACRO }  Object dialog() {     Dialog dialog = super();     ;      // Add a field for a name to the dialog. This will populate the field with      // any value that happens to be saved in name from previous uses of the     // dialog.     dialogName = dialog.addFieldValue(TypeId(Name), name);      return dialog; }  boolean getFromDialog() {     ;      // Retrieve the current value from the dialog.     name = dialogName.value();      return true; }  boolean validate(Object _calledFrom = null) {     boolean isValid;      isValid = super(_calledFrom);       // Perform any validation nessecary.     if (name != 'abc')     {         isValid = checkFailed('Name is not equal to abc') && isValid;     }      return isValid; }  Name parmName() {     ;      return name; }  public container pack() {     return [#CurrentVersion,#CurrentList]; }  public boolean unpack(container _packedClass) {     int version = conpeek(_packedClass, 1);      switch (version)     {         case #CurrentVersion:             [version,#CurrentList] = _packedClass;             break;         default :             return false;     }      return true; }  public static void main(Args args) {     DialogExample DialogExample;     ;      dialogExample = new dialogExample();      // Display the dialog. This only returns true if the the user clicks "Ok"      // and validation passes.     if (dialogExample.prompt())     {         // Perform any logic that needs to be run.         info(dialogExample.parmName());     } }
Typically in this scenario logic that needs to be run would be put in a run method on the class and then called into from main if the Ok button is clicked. Since the run method would be an instance method this gets rid of the need for the parm methods to access the value of the field on the dialog.