mardi 31 mai 2011

How to pass parameters from SalesTable Form to SalesFormLetter class

Here is a sample :

static void  main(Args  args)
   

    formrun           fr;
    Object             callerForm;
    ;

    if (! args)
        throw error("@SYS25407");

    if(record.TableId == tablenum(SalesTable))
    {
        fr                = args.caller();
        if( fr.args().parm() == '1')
        {
            Proforma        = true;
        }
        else
        {
            Proforma        = false;
        }
        args.parm(fr.args().parm());
        globalCache.set(curuserid(), 1, Proforma);
    }
    else
    {
        callerForm = args.caller();
    }

.
.
.

in the clicked method of a menuItem of SalesTable Form Button, we have this code

void clicked()
{

    boolean             ProformaOk;
    Args args           = new Args();
    ;
    element.args().parm('1');
    super();
}

mercredi 25 mai 2011

How to add range in an executeQuery of a dataSource

Here is an example:

public void executeQuery()
{
    QueryBuildRange    queryBuildRange;
    ;
    queryBuildRange = Projcategory_ds.query().dataSourceTable(tablenum(Projcategory)).findRange(fieldnum(Projcategory,Categorytype));
    if(!queryBuildRange)
    {
        queryBuildRange = Projcategory_ds.query().dataSourceTable(tablenum(Projcategory)).addRange(fieldnum(Projcategory,Categorytype));

    }
    queryBuildRange.value(queryValue(ProjCategoryType::Item));
    super();
}

jeudi 12 mai 2011

How to avoid inserting duplicated data in a table in dynamics ax using CSV file

Here is a method that illustrates how to insert data that does not exist in a table :

static void import_Dimensions_PIRECO(Args _args)
{
    Dimensions                                  dimensions;

    container                                   c;
    TextIo                                      io;
    str 250                                     fileName;
    int                                         inc;
    TextBuffer                                  b;
    Sysdim                                      num;
    DimensionCode                               DimensionCode;
    int                                         diff,niv1,niv2,niv3,niv4,niv5,pos;

    str InsZero(Sysdim input,int niv)
    {
        pos =0;
        diff = niv - StrLen(input);

        while (pos < diff)
        {
            input = strins(input,"0",1);
            pos++;
        }
            return input;
    }

    ;
     niv1 = 2;
     niv2 = 2;
     niv3 = 4;
     niv4 = 4;
     niv5 = 6;

     fileName = @"D:\AXS\GELBADR\Livrable\ThyProjet_codification_COST_CODE_v2.1.csv";
     b=new Textbuffer();

     io = SysLicenseCodeReadFile::openFile(fileName,'r');
     if (!io)
        throw error(strfmt("@SYS18678",fileName));
     io.inFieldDelimiter(";");
     c = io.read();
     while (io.status() == IO_Status::Ok)
     {
         c = io.read();
         inc++;
         if (io.status() != IO_Status::Ok)
         break;

         if ((conpeek(c,1) != "") && (conpeek(c,2) != ""))
         {
            num = conpeek(c,1);
            num = InsZero(num,niv1);

            DimensionCode = Sysdimension::Niveau_I;
            select firstonly dimensions
                where dimensions.Num           == num
                  &&  dimensions.DimensionCode == DimensionCode;
            if (!dimensions)
            {
                dimensions.Num = conpeek(c,1);
                dimensions.Description = strRem(conpeek(c,2),'"');
                dimensions.DimensionCode = Sysdimension::Niveau_I;
                print conpeek(c,1),"   ",conpeek(c,2);
                dimensions.insert();
            }
         }

         if ((conpeek(c,3) != "") && (conpeek(c,4) != ""))
         {
            num = conpeek(c,3);
            num = InsZero(num,niv2);

            DimensionCode = Sysdimension::Niveau_II;
            select firstonly dimensions
                where dimensions.Num           == num
                  &&  dimensions.DimensionCode == DimensionCode;
            if (!dimensions)
            {
                dimensions.Num = conpeek(c,3);
                dimensions.Description = strRem(conpeek(c,4),'"');
                dimensions.DimensionCode = Sysdimension::Niveau_II;
              //  print conpeek(c,1),"   ",conpeek(c,2);
                dimensions.insert();
            }
         }

         if ((conpeek(c,5) != "") && (conpeek(c,6) != ""))
         {
            num = conpeek(c,5);
            num = InsZero(num,niv3);

            DimensionCode = Sysdimension::Niveau_III;
            select firstonly dimensions
                where dimensions.Num           == num
                  &&  dimensions.DimensionCode == DimensionCode;
            if (!dimensions)
            {
                dimensions.Num = conpeek(c,5);
                dimensions.Description = strRem(conpeek(c,6),'"');
                dimensions.DimensionCode = Sysdimension::Niveau_III;
              //  print conpeek(c,1),"   ",conpeek(c,2);
                dimensions.insert();
            }
         }

         if ((conpeek(c,7) != "") && (conpeek(c,8) != ""))
         {
            num = conpeek(c,7);
            num = InsZero(num,niv4);

            DimensionCode = Sysdimension::Niveau_IV;
            select firstonly dimensions
                where dimensions.Num           == num
                  &&  dimensions.DimensionCode == DimensionCode;
            if (!dimensions)
            {
                dimensions.Num = conpeek(c,7);
                dimensions.Description = strRem(conpeek(c,8),'"');
                dimensions.DimensionCode = Sysdimension::Niveau_IV;
             //   print conpeek(c,1),"   ",conpeek(c,2);
                dimensions.insert();
            }
         }

         if ((conpeek(c,9) != "") && (conpeek(c,10) != ""))
         {
            num = conpeek(c,9);
            num = InsZero(num,niv5);

            DimensionCode = Sysdimension::Niveau_V;
            select firstonly dimensions
                where dimensions.Num           == num
                  &&  dimensions.DimensionCode == DimensionCode;
            if (!dimensions)
            {
                dimensions.Num = conpeek(c,9);
                dimensions.Description = strRem(conpeek(c,10),'"');
                dimensions.DimensionCode = Sysdimension::Niveau_V;
                //print conpeek(c,1),"   ",conpeek(c,2);
                dimensions.insert();
            }
         }

      }
}

mercredi 4 mai 2011

How to display the list of years in lookup

Take a combobox in the form and make autodeclaration to yes for that combobox...

In the form init write the code as

public void init()
{
    int             i,curyear;
    ;
    super();
    for(i= 0 ; i<=10; i++)
    {
        curyear = 2011 + i;
        ComboBox.insert(int2str(curyear),i);
    }

}

Follow this link to get more information about lookup.

How to create a list in dynamics AX and how to combine two lists

List Class

Contains any number of elements that are accessed sequentially.
Lists are structures that can contain values of any X++ type.
All the values in the list must be of the same type. Type is defined when the list is created and cannot be changed.

All X++ types can be accessable using enum Types::

Lists can be traversed by using the Enumerator , ListEnumerator class. To create a ListEnumerator object, use List.getEnumerator.

First Example
    List list = new List(Types::Integer);
    Enumerator en ;
    list.addEnd(333333); // add the value at last
    list.addEnd(111111);
    list.addEnd(222222);
    en = list.getEnumerator();
    print list.elements(); //"print number of element"
   
    while (en.moveNext())
    {
    print en.current();
    }
    pause;
Second Example
    List list1  = new List(Types::Integer);
    List list2  = new List(Types::Integer);
    List combinedList  = new List(Types::Integer);
    int  i;
    ;
    for(i=1; i<6; i++)
    {
        List1.addEnd(i);
    }
     for(i=6; i<11; i++)
    {
        List2.addEnd(i);
    }
    combinedList = List::merge(list1, list2);
    print combinedList.toString();
    pause;

How to customize a lookup List in Dynamics AX

Download this project and make the appropriate changes 

http://cid-e5871abbdbd5cc92.office.live.com/self.aspx/Public/DynamicsAX/Tutorial%5E_LookupMethods.xpo

mardi 3 mai 2011

How to insert Employees in Module of HRM and Pay with all details

You find here a class and a job that could help when importing data from CSV or Excel file to AX
http://www.megaupload.com/?d=YG6R2NIZ

To import Employees to HRM Module with their addresses surely you may need these tables:

1.Empltable
2.DirPartyTable
3.HRMVirtualNetworkTable
4.DirPartyAddressRelationshipMapping
5.DirPartyAddressRelationship
6.Address
7.HRMPartyEmployeeRelationship

Import the EmplTable -increment the partyid field
Import the DirParty table - increment the partyid field to match empltable
Import the Address table - the Reference field = Rec ID field on EmplTable
Import the DirPartyAddressRelationship1_1 table - using the partyid
Import the DirPartyAddRelMapping1_1 table - Reference (1st one) = RecID from Address table - Reference (2nd one) = RecID from DIRPartyAddressRelationship
Import the HRMPARTYEMPRELATIONSHIP table - Employee = Employee ID

dimanche 1 mai 2011

How to pass parameters from form to report

On the Button Clicked method:

void clicked()
{

    Args args = new args();
    ReportRun       reportRun;
;

    args.parm(SMAServiceOrderTable.ServiceOrderId);

    args.name(reportstr(GAB_ServiceOrder_NO));
    reportRun = classFactory.reportRunClass(args);
    reportRun.init();
    reportrun.run();

    super();
}

And then on the init method on the report;

public void init()
{
;
    try
    {
          if(element.args().parm())
          {
                this.query().dataSourceTable(tablenum(SMAServiceOrderTable))
               .addRange(fieldnum(SMAServiceOrderTable,    ServiceOrderID)).value(element.args().parm());

               this.query().userUpdate(false);
               this.query().interactive(false);
               super();
         }
     }

     catch(exception::Error)
     {
           info("Error in init method");
     }

}

Happy Daxing!

How to assign parameter in code when menu item is clicked

You can override method clicked on the button and put the following code
there:

MenuFunction menuFunction;
Args args = new Args();
;
menuFunction = new MenuFunction(menuitemactionstr(yourMenuItem),
MenuItemType::Action);
args.parm(someValue); //or parmEnum
menuFunction.run(args);