Monday, 31 March 2014

Models and Model store in ax 2012

Model and Model store : 


>> The earlier release of Microsoft Dynamics AX stores the metadata in the application files which is AOD files.  

>> In AX 2012 all the file based AOD files are replaced by SQL Server database based, which are called by Model Store.


Models and Model Files : 


>> Models are logical group of element like tables and classes.   In AX 2012 elements can be group and store in the model file.
>> Model files are easy to create, export, import and this can be uninstalled from the system when not required.
>> Each layer consists of one or more models. Each layer contains one system-generated model that is specific to that layer.
>> Every element in a layer belongs to only one model. In other words, no element can belong to two models in the same layer, and every element must belong to a model.
>> A default model owned by Microsoft exists in each layer. Default models cannot be modified.
>> A model is permanently associated with the layer that the model was created in.
>> If you need to move one of your models from one layer to another, you must create a project from the model in the Application Object Tree (AOT), export the project as an xpo file, create a target model in the desired layer, delete the original model to avoid having to resolve layer conflicts, and import the xpo file to the target model. If you are moving elements between models in the same layer, you can use the Move to model command in the AOT.

>> Models are stored in the model store. The model store is a database in which all application elements for Microsoft Dynamics AX are stored.
>> Customizations are also stored in the model store.
>> The model store replaces the Application Object Data (AOD) files that were used in earlier versions of Microsoft Dynamics AX.
>> Models that have been installed in the model store are used at run time.

>> In Microsoft Dynamics AX 2012 R2, the model store was moved into a database that is separate from the business database.

>> Models were introduced in Microsoft Dynamics AX 2012 to help partners and customers more easily install and maintain multiple solutions side by side in the same layer.

Hope this info. proves to be helpful to you... :)

Saturday, 29 March 2014

List, Set and Map in Dynamics Ax 2012 (Collection classes)

List :

      - It will hold similar datatype
      - Imp methods - elements. addstart, addend

Limitation of list - it will give in the order u/developer add - ascending or descending order  it all also allow duplicates


static void TDS_ListExample(Args _args)
{
    List l = new List(Types::String);
    ListIterator li;
    ;
   
    // limitation of list - it will give in the order u add - ascending or descending order
    // it all also allow duplicates
   
   
    l.addStart("Tendulkar");
    l.addEnd("sehwag");
    l.addEnd("gambhir");
    l.addEnd("yuvraj");
    l.addStart("haribhajan");
    l.addend("haribhajan");
   
    info(int2str(l.elements()));
   
    li = new ListIterator(l);
   
    while (li.more()) // this will return true or false -
    {
        info (li.value());
        li.next();
    }
   

}

Set : 

      - To overcome the limitations of list, we can use sets

static void TDS_SetExample(Args _args)
{
    Set s1 = new Set(Types::String);
    SetIterator si;
   
    Set s2 = new Set(Types::String);
   
    Set resultSet;
   
    // set will always result in ascending order and it will not allow duplicates
    // set can perform additional operations - union , intersection and difference
   
   
    s1.add("A");
    S1.add("z");
    s1.add("B");
    s1.add("F");
    s1.add("F");
   
    // To find any value in a set use "in" method
    if (s1.in("b") == true)
    {
        info ("b exists");
    }
    else
    {
        error ("b doesnt exists");
    }
   
   
    s2.add("A");
    s2.add("k");
    S2.add("g");
   
    info(int2str(s1.elements()));
   
    si = new SetIterator(s1);
   
    while (si.more())
    {
        info(si.value());
        si.next();
    }
   
    resultSet = Set::intersection(s1, s2);
   
    si = null;
   
    info ("Intersection");
    si = new SetIterator(resultSet);
   
     while (si.more())
    {
        info(si.value());
        si.next();
    }

   
}


Map : 

        - Map can hold a key and associated value
        - Imp methods : elements, Key, insert

static void TDS_MapExample(Args _args)
{
    // Maps are used to hold the key and correspondiong value
   
    Map m = new Map(Types::Integer, Types::String);
    MapIterator mi;
    ;
   
    m.insert(100, "Nick");
    m.insert(200, "Leo");
    m.insert(400, "Eve");
   
    mi = new MapIterator(m);
   
    while (mi.more())
    {
        info(mi.key());
        info(mi.value());
        mi.next();
    }
}

Another example to load all the records from the table to the map

Here key is accountNumber which is tring and associated value is creditlimit which is real

static void MAP_LoadTableTable(Args _args)
{
   Map m = new Map(Types::String, Types::Real);
   MEE_CustTable k;
   MapIterator mi;
 
 
   ;
 
   while select k
   {
        m.insert(k.CustomerId, k.Creditlimit);
   }
 
   info(int2str(m.elements()));
 
   info ("_______________________");
 
    mi = new MapIterator(m);
   
    while (mi.more())
    {
        info(mi.key());
        info(mi.value());
        mi.next();
    }

}


For all the classes , use iterator classes to print or get the values
ListIterator, MapIterator, SetIterator.

Note : Containers, List, Set and Map all together are called as collection classes in Dynamics Ax 2012. 

Hope u find this data useful... :)




Containers in Ax 2012 with examples.

Containers :

  - Containers are used to store different datatypes
  - Max columns in a container - 50

>> some important functions :

conlen - gives the length of the container
conpeek - gives the value of an element based on the index
conpoke - used for replacing any element with new element value
condel - willl delete the elements in cotnainer based on the start postion and number of elements to be deleted
connull - will empty the container
conins - will help to insert new elements to container
conview - to viuew the elements in the container - onyl for unit testing

confind - to find a particular element exists in container - it will give u the postiion/index

>> Just look at the following example to undestand how these methods can be applied :

static void TDS_Containers(Args _args)
{
    Container con = [1000, "Rahul", 5000.00, 56];
    container resultCon;
    int i;
    int position;
    // container limit is 50 columns
    ;
   
    // container index starts with 1
   
    // to get the length of the container
    info(int2str(conlen(con)));
   
    // to get any value based on the index use conpeek() function
    info(conpeek(con, 3));
   
    // to get all the values in one shot
   
    info("__________________________________");
   
    for ( i = 1; i <= conlen(con); i++)
    {
        info(conpeek(con,i));
    }

    info("__________________________");
   
    resultcon = condel(con, 2,2);
   
    conview(resultcon); // this should be only used for testing purpose
   
    // to nullify to empty the container
   
    //con = connull();
   
    //info(int2str(conlen(con)));
   
    //
    // To insert any new valuezs into container - use conins()
    // To replace any value in the container - use conpoke()
    // to find any value in container- use confind
   
    position= confind(con, "sreedhar");
   
    info(strfmt("sreedhar is found at %1 position", position));
}

Hope u find this useful... :)

Wednesday, 5 March 2014

Delete actions with example.

There are three types of Delete actions :

- None : The row in this table is deleted but nothing occurs in the specified table.

- Cascade : The row in this table is deleted and all the releated data in the specified table is also deleted. This ensures that no orphaned records remain after the deletion.

- Restricted : The row in this Table is only deleted if there is nothing that releats to it in the specified table. This is used when parent record should only be deleted when no child record exists, and the child record is important to keep.

- Cascade +Restricted : Behaves the same as restricted.

Advantage -

1. Data integrity -  Prevent Orphaned records (No meaningless data in database)

 Delete actions rely upon relations. First we create a relation between tables , and then create a delete action.

Delete actions are defined on Master table, you must have proper relations between tables, to perform delete actions.

 student master
Table :   studentclassdetails    studentmarkstable

Restricted says, look there is a marks record and u cannot delete a record in class table
Cascade says, okay delete a record in class table, so record in marks table are also deleted.


Example :

1. Create 3 tables
i) StudentMarksTable - 3 fields
StudentId- string, semester- string, subject -string, marks -int
                ii) Student Table
Id- string, Name- string
iii)GlobalstudentsTable
Studentid(string), name-string

Relations on StudentMarksTable, with studenttable Normal
Relation on studentable with global students table Normal


 Hope you find the data useful... :)

Table collection and Virtual company in Ax 2012

Table collections and virtual company
_____________________________________

In order to share the table data across the companies,
we will use table collections in combination with virtual companies

Create a new table by name "TS_VendorTable" and add 4 fields [VendorId, Name, Age, CreditLimit]

Go to AOT >> DataDictionary >> Table collections >> RC >> New Table collection >> Rename it to TSTC

Drag and drop TS_VendorTable table to the table collection

[Please note: Please do not add data in the table, there are high chances that data will be lost]

Go to SystemAdministration >> Setup >> Virtual company accounts >> Create a new virtual company by name "TsAc" and description as "virtual company accounts data - TS" and save the record.

Once you save the record, automatically you will find two other tabS [Company accounts, Table collections activated]

select some company accounts from right list to left list [ ceu, hyd, dat etc]
select TSTC collection from right list to left list.

Close the form, AX Client will shut down automatically.

Open new client to see HOW the sharing happens

sharing will actually happen with a field "dataareaid" in the table

data area id will be the virtual company account - "TsAc" for all those company which share the table collection.

Note : TS are my initials

Hope you find this info useful.... :)