Thursday, 20 July 2023

CRUD Operation in X++

 Insert and Select Statement



static void insert(Args _args)
{

    AttEmployeeTable     attEmployeeTable;  ;       //declaring a table buffer

    

    attEmployeeTable.EmployeeId = "Emp100";

    attEmployeeTable.Name = "Rahul";

    attEmployeeTable.Phone = "9897888821";

    

    attEmployeeTable.insert(); // inbuilt

    info("Record has been inserted");

}

 

static void bulkInserts(Args _args)
{

    ATTEmployeeTable    attEmployeeTable;    

    for ( int i = 1 ; i <=100; i++)

    {

        attEmployeeTable.AcccountNumber = "Emp" + int2str(i);

        attEmployeeTable.Name = "Rahul";

        attEmployeeTable.Phone = "9897888821";

    

        attEmployeeTable.insert(); // inbuilt      

    }

    info("Record has been inserted");

}



static void LearnSelectStatements(Args _args)

{

    AttEmployeeTable  attEmployeeTable;    

    Select * from attEmployeeTable;    

    info(attEmployeeTable.EmployeeId);

    

    // Select latest record

    select * from attEmployeeTable order by RecId desc;    

    info(attEmployeeTable.EmployeeId);

    

    // select a particular record    

    select * from attEmployeeTable where attEmployeeTable.EmployeeId == 'SIS99';

    info(attEmployeeTable.EmployeeId);

    

    // MULTIPLE RECORDS FETCHING - while select      

    while select * from attEmployeeTable where attEmployeeTable.Gender == Gender::Male

    {

        info(attEmployeeTable.EmployeeId);

    }

  

    // fieldslist  --  select the fields which u want to display or use further    

    select Name from attEmployeeTable where attEmployeeTable.EmployeeId == 'Emp99';

    info(attEmployeeTable.EmployeeId);    

    //infolog.clear();      

}





Update and Delete Statement


static void UpdateQuery(Args _args)
{

    CustTable custTable;    

    ttsBegin;

    select forupdate custTable where custTable.AcccountNumber == 'ATT100';

    if (custTable)

    {

        custTable.Name = "New name";

        custTable.update();

    }

    ttsCommit; //ttsabort

}



static void UpdateQueryMultiple(Args _args)
{

    CustTable custTable;    

    ttsBegin;

    while select forupdate custTable //where custTable.AcccountNumber == 'ATT100';

    {

        custTable.Name = "New name";

        custTable.update();

    }

    ttsCommit; //ttsabort

 

    // roundtrips to sql is no of records + 1

    // performance improvement - update_recordset

    

    update_recordset custTable setting Name = "New Name again";

    // you can even add where clause

}



static void deleteQuery(Args _args)

{

    SISCustTable custTable;    

    ttsBegin;

    while select forupdate custTable //where custTable.AcccountNumber == 'ATT100'

    {

        custTable.delete();

    }

    ttsCommit; //ttsabort

    

    // roundtrips to sql is no of records + 1

    // performance improvement - delete_from

    

    delete_from custTable;

        // you can even add where clause

}



 


Monday, 17 July 2023

Tables in D365

 

Tables

Steps: 

·       Create New Project -- Right click and create new table (AttEmployeeTable)

·       Expand the newly created table and you will find a new field’s node.

·       Drag and drop all the extended datatypes which you want as field to field’s node, for all fields - label and help text are important.

             You can even drag and drop the Enum on to the table - it will create a new enum field.


Important properties on the field:

Label

HelpText

Mandatory

AllowEditonCreate

AllowEdit

Visible

EDT

EnumType

 

The system will automatically create 4 new fields in every table:

DataAreaId - current logged in company

Recversion - int64 - for concurrent updates

RecId - int64 - unique record id [when u save a record - interview & certification question]

Partition Id


Why indexes ?

Index will help you for performance for select statements [Improve performance of select statements]. In Ax It also doesn’t allow duplicates

 

How to stop adding duplicates - Restrict the redundancy of data

·       Go to Index node in the table >> right click and new Index >> Drag and drop the EmployeeId field to newly created index.

 

·       Best practise [MS Recommends - ] Index name should Have the prefix as your fieldname and suffix as Idx – EmpoyeedIdx

 

·       Set the allow duplicates property to No

 

Field group:

Grouping up of similar fields for easy identification in one place.

Right click on the field groups >> New Group >> Give the Name as AddressInfo, label as Address information

Drag and drop all address related fields to the newly created field group

 

AutoReport:

AutoReport field group will help to quickly generate a Excel Add-in & report based on the fields whatever you have dragged and dropped in to it

Drag and fields to the AutoReport


Important Tables:

CustTable - The table for basic customer information.

VendTable - The table for basic vendor information.

LedgerTable - The table for the general ledger it have chart of accounts information.

InventTable - The table for the general inventory information.

PurchTable - The table for purchase order creation information.

SalesTable - The table for sales order creation information.

Chain of Command

 

Chain of Command

Add a new class in project, Add access modifier as final to class.

Add attribute to class [ExtensionOf(classStr(InventTable))]

We can change attribute for Tables, Forms, Queries etc ... For table - TableStr, Form - FormStr


Add method same as in base class, with same method signature.

Next keyword is used to call base class.

 

[ExtensionOf(classStr(PdmEcoResProductReleaseManager))]

final class ATTPdmEcoResProductReleaseManager_Extension

{

    protected void createInventTable()

    {

        InventTable inventTable;

        next createInventTable();

        if (mEngineeringInventTable)

        {

            ttsbegin;

            inventTable = InventTable::find(ecoResProduct.productNumber(), true);

            if (inventTable)

            {

                inventTable.initFromEngineeringInventTable(mEngineeringInventTable);

                inventTable.doupdate();

            }

            ttscommit;

        }        

    }

}

Customizing Standard Object in D365FnO

 

Customizing Standard Object

In Dynamics AX 2012 we can modify/Customize any objects directly by adding in project an make the required changes. It is called as over layering approach but in D365 over layering is not allowed for standard objects

To modify any standard object we have to create extension of the object. Although there are many limitation when we create extension of an object.

There are also other processes to customize objects, they are

  •    Chain of commands
  •    Event Handlers
  •   Delegates

 

Creating Extension:

Add a new project in solution explorer and change the model.

To create an extension of an object right click on the object and click on Create extension



EDT (Extended Data type)

 

Extended Data Types (EDTs)


Extended data types (EDTs) are user-defined types, based on the primitive data types Boolean, integer, real, string, and date, and the composite type container. You can also base EDTs on other EDTs. 

This feature is not implemented as a language construct. EDTs are defined in the Application explorer (AOT). 

An EDT is a primitive data type or container with a supplementary name and some additional properties. For example, you could create a new EDT called Name and base it on a string. Thereafter you can use the new EDT in variable and field declarations in the development environment. 


Benefits of EDTs


The benefits of EDTs are as follows: 

  • Code is easier to read because variables have a meaningful data type. For example, Name instead of string. 

  • The properties you set for an EDT are used by all instances of that type, which reduces work and promotes consistency. For example, account numbers (AccountNum data type) have the same properties throughout the system. 

  • You can create hierarchies of EDTs, inheriting the properties that are appropriate from the parent and changing the other properties. For example, the ItemCode data type is used as the basis for the MarkupItemCode and PriceDiscItemCode data types. 




Thursday, 13 July 2023

Object Oriented Programming (OOPS )

 

 

OOPS (Object Oriented Programming)

 

Classes - A class is software construct that defines the data, grouping up of similar objects.

Method - Methods are the functions that operate on the data and define objects behavior.

Variables – Variables are used to store the data for the class, they are specific to an object.

 

Class declaration: Specifies the name of the class and necessary variables, It can also specify inheritance.

Static: Static methods are methods that are called on the class itself, means an instance of class is not required to call these methods. 

Void: This datatype show that the return value is null.

Main: This is the method from where the execution of code get start. A class in order to execute on its own, should have a main method.

New() – This method initiates a new object, you can also assign values to the object variable using this method.

Construct() - The method should return an instance of the class.

 

Class ClassName
{

     public void main(Args _args)
     {

     }

}

 

Public – Access Modifier

Void – Return Type

Main – Method name

Args – Parameter


Global and Local Variables:

A scope defines the area in which an item can be accessed. Variables defined in a class are available to the methods within that class. Variables in methods can be accessed only within the current Method

Class ClassName
{

     Int a; ----- Global variable (Can be used in any of the method defined in this class

     public void main(Args _args)
     {

           Int b; ------ Local variable (Can be used only in this method)

     }
}

 

Creating object of class:

ClassName objectName = new ClassName();

 

Calling method through object

ClassName objectName = new ClassName();

objectName.MethodName();

 

Calling Static method:

ClassName::MethodName()

RunnableClass1::Main();

 

Constructor – In X++ constructor is a static method which is used to call instance of the class.

Class ClassName
{

     public static void Construct()
     {

            return new ClassName();

     }

}

Call a constructor

ClassName className = ClassName::Construct();

 

Parameterized Construct

public static void Construct(Args _args)
{

    ConstructClass  contructClass = ConstructClass::construct("icici");

 }

  

Inheritance

 

Inheritance is an important concept in X++. Inheritance is a concept in which you define parent class and child class relationship.

The child classes inherit methods of the parent class, but at the same time, they can also modify the behaviour of the methods if required. The child class can also define methods of its own if required.

In X++ inheritance is done using keyword “extends”. “Super” keyword is used to call parent class method in child class. To Stop a class from being inherited use keyword ”Final”.

X++ supports single inheritance, but it does not support multiple inheritance. X++ supports overriding, but it does not support overloading.

Class ParentClass
{

     public void helloWorld()
     {

         info(“Hello World”);

     }
}

Class ChildClass extends ParentClass
{

     public void helloWorld()
     {

super();

     }
}


Abstract Class & Method

Abstract classes are marked by the keyword abstract in the class definition, they are typically used to define a base class in the hierarchy. We can't create an instance of them

Mostly, an abstract class is used to define what is known as a base class. A base class is a class which has the most basic definition of a particular requirement.

An abstract class can have both abstract methods and Non Abstract methods.

 

Abstract Method
When declare a method as 
abstract this method should be declare/initiate in child class. Abstract methods only be declared in abstract classes. No code or declarations are allowed in abstract methods.

 

abstract class AbstractClass
{

      abstract void myAbstractMethod()
      {

      }
}

 

Class ChildClass extends AbstractClass
{

     void myAbstractMethod()
     {

     }
}

 


Interface

An interface is a method that contains only method signature, it doesn’t contains any code in it. Interface can be accessed by using keyword Implements, we can implement multiple interface at a time using comma separator.

An interface can extend another interface by using extends keyword. An interface cannot extend more than one interface.
The purpose of interfaces is to define and enforce similarities between unrelated classes without having to artificially derive one class from the other.

All methods in Interface are public in nature.

 

Interface InterfaceClass
{

      void myInterfaceMethod()
     {

     }
}

 

Class ChildClass implements InterfaceClass
{

     void myInterfaceMethod()
     {

             // Write your code

     }
}

 

 

 

 

 


Sunday, 9 July 2023

Primitive Data types

 

Primitive Data Types

The primitive data types in X++ are listed in the following table. For more information about each data type, click its link.

Anytype

A placeholder for any data type.

Booleans

The boolean data type contains a value that evaluates to either true or false. You can use the X++ reserved literals true and false where ever a Boolean expression is expected.

Dates

Contains day, month, and year. The date data type can hold dates in the closed interval [1\1\1900; 31\12\2154], that is: between January 1, 1900, and December 31, 2154.

Enums

An abbreviation for enumerated text—a set of literals. Enum values are represented internally as integers. The first literal has number 0, the next has number 1, the next has number 2, and so on. You can use enums as integers in expressions.

 

Integers

A number without a decimal point. To declare an integer, use the keyword int.

Integers are numbers without decimals. X++ has two integer types:

  • int, which is 32 bits wide
  • int64, which is 64 bits wide

 

Reals

Numbers with a decimal point; also called decimals.

Strings

A number of characters. To declare a string, use the keyword str.

Strings are sequences of characters that are used as texts, help lines, addresses, telephone numbers, and so on. To declare a string in X++, use the str keyword.

A string can hold an indefinite number of characters. If you know the absolute maximum of characters a string will hold, you can specify this in the variable declaration and force a truncation to the maximum length of the string.

TimeOfDay

Contains hours, minutes, and seconds. To declare a time, use the system type timeOfDay.

utcdatetime

Contains year, month, day, hour, minute and second.

 

The utcdatetime data type is intrinsic to X++. It combines date and timeOfDay types into one type. A utcdatetime variable also holds time zone information, though this information is not accessible to X++ code.

Range and Precision


The following table describes the range and precision of the utcdatetime data type.

Attribute of utcdatetime

Description

Precision

The smallest unit of time in utcdatetime is one second.

Default and Null

1900-01-01T00:00:00

A utcdatetime variable that has been declared but not initialized has the default value of 1900-01-01T00:00:00. This is the value returned by DateTimeUtil ::minValue().

Some functions treat an input parameter of this minimum value as null. For instance, the DateTimeUtil ::toStr method returns an empty string, however, the DateTimeUtil ::addSeconds method returns a fully usable utcdatetime value.

Minimum Value

1900-01-01T00:00:00

Maximum Value

2154-12-31T23:59:59

This matches the upper range of date and timeOfDay.

 

 

Working with X++

 

Working with X++ 

Static: Static methods are methods that are called on the class itself, means an instance of class is not required to call this methods. 

Void: This datatype show that the return value is null.

Main: This is the method from where the execution of code get start. A class in order to execute on its own, should have a main method.

Display messages - 

  •   info("Amount has been credited");
  •   warning("Insufficient funds");
  •   error("Transaction is aborted");


First Program

static void FirstJob(Args _args)
{
      str information;
      information = "Hello..Let’s learn ax"; 
      info(information);
}

Addition of Number - 

static void Additions(Args _args)
{
      int a = 10;
      int b = 20;
      int c;

      c = a + b;

       // conversion functions - int2str, str2Int

        info(int2str(c));

        // concatenation

        info("The result after addition is " + int2str(c));
}


If Else condition

static void IfElseExample(Args _args)
{

         AmountMST amount = 150;   

         if (amount > 200)

    {

        info("You can watch a movie");

    }

    else

    {

        throw error("Insufficient money");

    } 

    info("I have seen the show.Movie is good");

}


If ElseIf else -

static void ifLoop(Args _args)

{

        int age = 10;

        if (age <= 2)
        {
                info("Still a baby");
         }
         else if (age >2 && age <=19)
         {
                info("Teenage");
         }
          else if (age >=20 && age <=45)
         {
                info("MIDDLE AGE");
         }
        else
        {
                info("Old age");
        }

}

 

Loops - (For loop & While loop)

static void LoopsInAX(Args _args)
{ 

    int i = 1;   

   //For loop

    for (i = 1; i <=4 ; i++)

    {

        info("Eating");

    }

 

//While Loops

    i = 1;   

    while (i <=4)

    {

        info("Eating");

        i++;

             }

}

 

Switch Case

static void swtichCaseExample(Args _args)

{

    Gender genderType = Gender::Male;   

    switch(genderType)

    {

        case Gender::Male  : info("I am male"); break;

        case Gender::Female  : info("I am female"); break;

        case Gender::NonSpecific  : info("I am Nonspe"); break;

        case Gender::Unknown  : info("I am unknown"); break;

        default: info("Incorrect value");
    }

}

 

Break and Continue 
static void breakAndContinue(Args _args)

{

    int i = 1;  

    for (i = 1; i <= 10; i++)

    {
        if (i == 5 )

            break; // continue;

        info("Hello" + int2str(i));

    }

}


String formatting - 

static void strfmtFunction(Args _args)

{

    // infolog can only print string datatype

    // if you want to print different data types in an infolog.
        You need to convert all the datatypes first in to string and then print

    //Example : I AM RAHU. MY AGE IS 20. MY SAL IS 5000.00

   

    info(strFmt("I AM RAHU. MY AGE IS %1. MY SAL IS %2", 20, 5000.00));

}








Data Entities in D365 FnO

  Data management - Data entities ·        Data entity is a conceptual abstraction and encapsulation of one of more underlying tables. ...