lundi 11 octobre 2010

How to add a tabpage in a dialog in Dynamics AX

We can add a new tabpage in the dialog using this code

How To create Dialogs using X++

We can instead of using froms create dialogs if we need to precise dates , years0, select employee(s), ..., fill your temporary table(s)  and then display your report. In such scenario you can make use of RunBase class. 

RunBase class  provides dialog for presenting and collecting the information from user and validates method , to validate the data entered by the user in the dialog.
I 've designed a  report.  I build a class"TmpPopulateClass" , and a method "populate" for example , I fill my table with the appropriate data and "populate" returns TmpTable. I call this method in my fetch report method. I set this temporary table as a datasource for my report.
I  got the fields year1, emplid from my dialog wich I created via "Dialog" and "GetDialog" methods in my report.









If  I use a textBuffer, I have ti initialize it in the init method.








Fields of the temporary table , can be used then in my report design.
Then I  put this report in the output menuitems. and I can display my dialog, call methods , fill tables via my dialog.












It is possible also to call another report using the same dialog although the feth method is created in only one report ,  we can also create two report designs in the same report and call one of them.


















As we see the two reports are diffrent and have diffrent datasource, thus I created a queryrun associated to each report . I fill in the datasource : temporary tables and according to informations in my dialogs I can display
my report.
 Resources

mercredi 6 octobre 2010

How to use TextBuffer in X++

We have for example a year as variable

PayrollPaySlipYear                       year0;

We are going to set a value to this variable.
We use this code :

PayrollPaySlipYear                       year0;
Str                                               date1;
year0 = new textbuffer();
date1="2010";
year0.setText(date1);

Some functions used in X++

strRem 
Removes the characters specified in one string from another string.  
str strRem(str text1, str text2) 
where 
text1 : The string from which to remove characters.
text2 : The characters to exclude from the output string.

subStr

Retrieves part of a string. 
str subStr(str _text, int _position, int _number) 
where
_text : The original string.
_position : The position in the original string where the part to retrieve begins.

_number : A signed integer that indicates the direction and number of positions to retrieve from the original string.
If there is a minus sign preceding _number, the system selects the substring backward from the specified position.

strDel  

Creates a copy of a string with the specified substring removed. 
str  strDel( str _text, int _position, int _number) 
where
_text  : The string to copy from
_position : The position at which to begin ignoring characters during the copy.

_number : The number of characters to ignore.
A minus in front of _number parameter indicates that the (_number-1) characters before the character at the _position parameter are to be removed along with the character at the _position.


strFmt

Formats the specified string and substitutes any occurrences of %n with the nth argument.

str strFmt(str _string, ...)
where 
_string  : The strings to be formatted.

example: to set the number of page in a report :

Display STR 20 pageNum()
{
    return StrFmt("@SYS24160", element.page());
}

num2Str 

Converts a real number to a string. 

str num2Str(
    real number,
    int character,
    int decimals,
    int separator1,
    int separator2)
where: 
number The real number to convert to a string.
character The minimum number of characters required in the text.
decimals The required number of decimal places.
separator1 A DecimalSeparator enumeration value.
separator2 A ThousandSeparator enumeration value.

 Example 

static void Job_Num2Str(Args _args)
{
    real realNum = 0.1294567890123456777; // 19 decimals places.
    ;
    info(Num2Str(realNum,0,16,1,3)); // 16 decimals
    info(Num2Str(realNum,0,17,1,3)); // 17 decimals
}
 
Round   
Rounds a real number to the nearest multiple of another real number.
real round(real _arg, real _decimals)
 
_arg The original number.
_decimals The number that the value of the _arg parameter must be rounded to a multiple of.
Examples:
  • round(123.45,5.00); //Returns the value 125.00.
  • round(7.45,1.05); //Returns the value 7.35.
  • round(23.9,5.0); //Returns the value 25.00;
  • round(26.1,5.0); //Returns the value 25.00;
strLen 

Returns the size of a string 

int strLen ( Str _text )

ConPeek

Retrieves a specific element from a container.

anytype conPeek(container container, int number)
Example:
static void conPeekExample(Args _arg)
{
    container c;
    int i;
    ;
 
    c = conIns(["item1", "item2"], 1);  
    for (i = 1 ; i <= conLen(c) ; i++)  
    {
        print conPeek(c, i);
    }
    pause;
}

strUpr

Converts all the letters in a string to uppercase. 

str strUpr(str _text)

static void strUprExample(Args _args)
{
    print strUpr("Abcdd55EFGhiJ");
    pause;
}

strLwr
Converts all the letters in a string to lowercase. 
str strLwr(str _text)

static void strLwrExample(Args _args)
{
    // Returns the text string "abcdd55efghij".
    print strLwr("Abcdd55EFGHIJ");
    pause;
}
Units  
 We use it to set the unit of a dimension.
Example : 
element.design().controlName("CustInvoiceJour_InvoicingName"); 
CustInvoiceJour_InvoicingName.top(20.8, Units::mm);

    Global::dateEndYr Method

    Retrieves the date of the last day in the same year as the specified date.  

    client server public static date dateEndYr(date transDate)

    Global::DateMthFwd Method

    Adds the specified number of months to a date. 

    client server public static date DateMthFwd(date transDate, int qty) 

    Global::DateStartYr Method 

    Retrieves the first date of the specified year. 

    client server public static date DateStartYr (date transDate)
     
    tableName2Id Function

    Retrieves the ID of a table. 

    int tableName2Id(str _name)
     
    Resources:
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true 

    
    

    How to add a Logo of a company in your report in Dynamics AX

    Go to Company > Basic > Basic Area > Setup and click Company information.
    Click on the button "Company Log"




    Click on the button " Change "  and then import the Logo of the company. Then when you are going use this Logo in your report for example just get a bitmap and set the data method to "CompanyLogo"



    How to get the FieldId of a variable in Dynamics AX

    You have just to look for the ExtendedDataType of this field and to use this :

    FieldId                                fieldId;
    fieldId = typeid("emplid");

    How to use a field of a form in Dynamics AX

    First of all you have to select this field and set Autodecalartion proprety toYes.










      Then, in your code use this code :

      Emplid                            employeeId;
     Str                               _value;  
     element.design().controlName(identifierStr(emplid));
     employeeId = emplid.text();

    But if you want to use it as an Str use this :

     _value= emplid.valueStr();

    mardi 5 octobre 2010

    How to Convert from String to Date and from Date to String in Dynamics AX

    We will read dates from  a table we will check if the date is null for that we will convert it to String using 'date2str'  to compare it with "".
    Then we will declare a date and insert it into this table3. In that case we have to convert a String to date we use ' str2date'. And you can of course personnalize the Separators and Date Format when converting from date to string 


    vendredi 1 octobre 2010

    How to import data of a client into a company in Dynamics AX

    1. Get Microsoft SQL Server installed in your PC.
    2.  Get the backup of Database of the client and import it to Microsoft SQL Server Management Studio.
    3. Create a new Database, then click
     Database > Tasks > Import Data...
    4. then you have to export tables into excel format 
    click  Database > Tasks > Export Data...
    then choose SQL native client as a Datasource.
     click next and then choose Microsoft Excel as a 
    a DataSource.


    5. click next then chhose the table you want to export and clich finish.
    Now, you have the table exported in Excel Format.
    Save it in CSV format to import the data to AX.














    6. To import Data to DAX, we will use CSV format.
    And then we use a job to import Data needed from CSV file to tables of DAX.

















    7. if you want to update from a table in DAX


    Note
    When you use the query select you don't have to use transactions : ttsbegin; and ttscommit , but you have to use that in case of delete or update queries.