Jan 25, 2012

Three rules when declaring variables in X++?


  1.  Declare all variables before anything else in the code
  2.  Use a ';' (semicolon) after each declaration.
  3.  Use a ';' (semicolon) to separate the declarations from the rest of
the code.

Classes & methods that can be created in X++ and their differences.



The different kinds classes in AX are as follows:

1 Application classes - we implement them in X++, and they are located at AOT --> Classes.

2 System classes (or kernel classes) - They are implemented in C++. The source for these classes is not available in AX.
Ex :- xSession , xApplication ,xCompany ,xInfo ,xClassFactory ,xGlobal ,xVersionControl

3 Application substituted kernel classes are extensions of system classes.
EX :- Session , Application ,Company ,Info ,ClassFactory ,Global ,VersionControl


Object methods can only be activated by an object that has been

instantiated from the specific class. An object method is called as

follows:

Class_name ref_name = new Class_name ();
ref_name.testmethod();


Class methods can be attached directly to a class and do not need an

instantiated object to work. Use the 'static' modifier when you create

class methods. A class method is called as follows:

Class_name::testmethod();

If a report attached to a form ,how can the report display the values of the selected one in form?


suppose i put my report on the  CustPackingSlipJour  form then i selected on e record,i want to display the information of that particular record only in my report then the following code helps    

public class ReportRun extends ObjectRun
{
    CustPackingSlipJour     externalCustPackingSlipJour;
}

public void init()
{
    element.initFromArgs(element.args());
    super();
}

void initFromArgs(Args args)
{
    if (args && args.dataset())
    {
        switch(args.dataset())
        {
               case tablenum(CustPackingSlipJour) :
                                        externalCustPackingSlipJour  =   args.record();        
        }
     } 
}

How to change the item if we want to change the item ?


  • Click stockManagement à Items
  • Rightclick the Item number field .
  • Select record info ,and then click rename.
  • Type the new item number 
  • Click Ok. 

How to convert the amount into words ?


display tempStr amountStr()
{
    if(netAmount <= 0)

    return   '-'+ ' ' + '(' + currCode + ') ' + numeralsToTxt(-(netAmount))+' '+'Only';

    else

    return   '(' + currCode + ') ' + numeralsToTxt_EN(netAmount)+' ' +'Only';
}

How to update only few records?


Sample code in X++ to update the few records...

Static void main updateIds(Args  args)
{
EmplTable  empltable;
 
Ttsbegin;
while select forUpdate EmplTable Index hint EmplIdIdx
                              where EmplTable.EmplId == ‘10001’;
If(emplTable.recId != 0)
{
    emplTable.EmplId = ‘10101’(New EmplId);
    EmplTable.renamePrimaryKey();
    EmplTable.update()
}
Else
{
    Info(‘employee not found’);
}
ttsCommit;
}

How to update the existing records?


For example to change old emplId’s with new emplId’s

Create CSV file with two columns – one Old EmplId ans second new emplId

Write a job to – step 1) Read the CSV file
                           step 2) the job should look for old EmplId’s
                           step 3) once the EmplId found it should replace with new EmplId

All long the job should keep a count of number of employees read and number of employees updated

How to get current time in AX ?


Simple code to display timeNow()  in X++ which returns current time

static void timeNowExample(Args _arg)
{
    TimeInMS  i;
    ;

    i = timeNow();
    info(time2str(i,0,0));

}
str time2Str( int _time, int _separator, int _timeFormat)

The parameters of the function time2Str are described as below:

_time            : The number of seconds since midnight.
_separator   : The characters to be used as separators in the text string. Possible values  follow:  
0 – regional settings for the operating system
1 – colon (:) 
2 – point (.)
3 – space ( )
4 – comma (,)
5 – forward slash (/)

_timeFormat  : Determines whether a 12-hour or 24-hour clock is used. Possible values  follow:

How to display date and time according to time zone ?


static void Job7(Args _args)
{
   ;
   //Current Date and Time according to time zone
   info(strFmt('%1',DateTimeUtil::newDateTime(systemdateget(),                                                                    timenow(),Timezone::GMT_CASABLANCA_MONTROVIA_REYKJAVIK)));

 //Todays Max Date and Time
info(strfmt("%1",DateTimeUtil::newDateTime(SystemDateGet(),Global::timeMax())));

}            

How to supress the infolog which opens after opening a report?


Write the following code in init()  of the report

                              this.printJobSettings().supressScalingMessage(true);

The report property ‘FitToPage’(Check under Design node) indicates whether resized to fit the width of the page

How to set the shared folder to VPC ?


In VPC à Edit à Settings à Shared folders à browse the location

If ur shared folders are disabled then run your VPC and click action à install all updated Virtual machines and install them ,after installation ur shared folders will be enabled