Showing posts with label AX 2012. Show all posts
Showing posts with label AX 2012. Show all posts

RecordInsertList Dynamics 365 Finance & Operations

 

RecordInsertList Dynamics 365 Finance & Operations



A shortcode example of how to can create records in a table very performant way using RecordInsertList. Who does not know RecordInsertList, can learn more about it here.

static void HowToUseRecordInsertList(Args _args)
{
    DMOPerfTest DMOPerfTest;
    RecordInsertList RecordInsertList;
    Counter c;
    FromTime fromTime = timeNow();
    
    RecordInsertList = new RecordInsertList(tableNum(DMOPerfTest));
    
    for (c=1;c<=10000;c++)
    {
        DMOPerfTest.clear();    
        DMOPerfTest.AccountNum = int2str(c);
        
        if(DMOPerfTest.validateWrite())
        {
            RecordInsertList.add(DMOPerfTest);
        }
    }
    
    RecordInsertList.insertDatabase();
    
    info(strFmt("Total time consumed: %1", timeConsumed(fromTime, timeNow())));
}

Support Faryal's Cusine


Bulk Database Operations Recordset D365FO/AX 2012

 

Recordset operations or set based operators



We all noticed that AX 2012 and D365FO get slow from time to time when we performed insertion or update operations on huge numbers of records one by one, and to overcome this issue, Microsoft has a feature to update or insert in bulk in a single statement.
 
We have 3 types of Bulk Operations
  • insert_recordset
  • update_recordset
  • delete_from

insert_recordset :


insert_recordset copies data from one or more tables directly into one resulting destination table on a single server trip. Using insert_recordset is faster than using an array insert. However, array inserts are more flexible if you want to handle the data before you insert it.

insert_recordset is a record set-based operator, which performs operations on multiple records at a time.

Syntax :


The list of fields in the destination table must match the list of fields in the source tables.
Data is transferred in the order that it appears in the list of fields.
Fields in the destination table that are not present in the list of fields are assigned zero-values as in other areas in X++. System fields, including RecId, are assigned transparently by the kernel in the destination table.

insert_recordset DestinationTable ( ListOfFields )

select ListOfFields1 from SourceTable [ where WhereClause ]

[ join ListOfFields2 from JoinedSourceTable

[ where JoinedWhereClause ]]

Example : 


The records, "myNum" and "mySum", are retrieved from the table another table and inserted into the table myTable. The records are grouped according to "myNum", and only the "myNum" records with a value less than or equal to 100 are included in the insertion.

insert_recordset myTable (myNum, mySum)
    select myNum, sum(myValue)
        from anotherTable
        group by myNum
        where myNum <= 100;


update_recordset :

The X++ SQL statement update_recordset enables you to update multiple rows in a single trip to the server. This means that certain tasks may have improved performance by using the power of the SQL server.

update_recordset resembles delete_from in X++ and to UPDATE SET in SQL. It works on the database server-side on an SQL-style record set, instead of retrieving each record separately by fetching, changing, and updating.


If the update method is overridden, the implementation falls back to a classic looping construction, updating records one by one just as delete_from does for deletions. This also means that the construction works on temporary tables, and whole-table-cached tables by using the looping construction.

Example :

MyTable tableBuffer;
;
update_recordset tableBuffer
setting field1 = field1 * 1.10;

delete_from :

You can delete multiple records from a database table by using a delete_from statement. This can be more efficient and faster than deleting one record at a time by using the xRecord.delete method in a loop.


If you have overridden the delete method, the system interprets the delete_from statement into code that calls the delete method one time for each row that is deleted.

Example :

static void DeleteMultiRow1aJob(Args _args)
{
    MyWidgetTable tabWidget;
    ;
    delete_from tabWidget
        where tabWidget .quantity <= 100;

}

But these set-based operations will roll back to row-by-row operation when either of the following condition is true:

  • it is not an SQL table (Eg. temporary table)
  • Database log is enabled for the table
  • Alert is set up for this table
  • Record level security is enabled for the table
  • AOSValidation method is overwritten

when using insert_recordset
the .insert() method is overwritten

when using update_recordset
the .update() method is overwritten

when using delete_from
the .delete() method is overwritten
DeleteAction is defined



To prevent it from fallback to row-by-row operation, the following method can be used if:

  • Delete action is defined, use skipDeleteActions
  • Database log is setup, use skipDatabaseLog
  • Alert is setup, use skipEvents
  • Method is overloaded (.insert(), .update, .delete()), use skipDataMethods



Support Faryal's Cusine


Definition of List, Set, Container, and Map

 

Difference between List, Set, Container, and Map


Containers:

Containers are dynamic and have no limits. They can contain elements of
almost all data types: boolean, integer, real, date, string, container,
arrays, tables, and extended data types. However, objects may not be stored
in containers.

Containers in AX are used very often. It’s easy to work with them. But…
data in containers are stored sequentially and thus retrieved sequentially.
This means that containers provide slower data access if you are working with
_large numbers_ of records. In case of large numbers of records use temporary
tables.

List:

Lists are structures that may contain any number of elements that are
accessed sequentially. Lists may contain values of any X++ type. All the
values in the list must be of __the same__(this is the main difference
between lists and containers) type, given in the creation of the list. The
implementation of lists is such that the traversal of the list elements is __very
fast.

Take a look for example at the class Dialog addControl() method.
Their controls are stored in ctrls List.

Map:

A map is a data type that associates one (key) value with another value [An
analog – a small table in memory with two fields: Keys, Values]. Both the key
and value values may be of any valid X++ type, including objects. The types
of the key and the value are given in the declaration of the map. The
implementation of maps is such that access to the values is _very fast_.

Don’t confuse map X++ types with Map objects in AOT, which are used for
mapping tables with similar structures of fields

Set:

The functionality of Sets is similar to the list.  A Set is just an unordered list of items, while a list of items held by a Map
are indexed via a key.
Take look at
\Classes\sysLabel\LabelModuleId().

Support Faryal's Cusine


intermediate language CIL IL D365FO


 What is an intermediate language?



Intermediate language (IL) is an object-oriented programming language designed to be used by compilers for the .NET Framework before static or dynamic compilation to machine code. The IL is used by the .NET Framework to generate machine-independent code as the output of the compilation of the source code written in any .NET programming language.

IL is a stack-based assembly language that gets converted to bytecode during the execution of a virtual machine. It is defined by the common language infrastructure (CLI) specification. As IL is used for the automatic generation of compiled code, there is no need to learn its syntax.

This term is also known as Microsoft intermediate language (MSIL) or common intermediate language (CIL).

Support Faryal's Cusine


Interfaces & Abstract Class

 

Interfaces VS Abstract Class?




The class implementing is the interface that implements all interface methods and there will not be any abstract Class requirement. There are many access modifiers available like abstract, protected, virtual, internal, public, and many more that are useful in the abstract Classes. Abstract classes will be very fast when compared to interfaces.


Abstract class contains both the incomplete or complete methods and the interface is the signature for a particular method. The abstract class is the implemented method but the interface cannot be an implemented method.


The abstract class contains constructors, fields, or destructors for implementing the properties. The interface does not contain constructors, fields, or destructors but they have only the property’s signature with no implementation.

The abstract class does not support multiple inheritances and the interface supports multiple inheritances. The class can also inherit more interfaces but only a single abstract class.

































Support Faryal's Cusine


Pass By Reference and Pass By Value

 

Difference Between Pass By Reference And Pass By Value?


Pass By Reference: 

In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect the actual parameters

  1. The same memory location is used for both variables. (Formal and Actual)
  2. It is useful when you are required to return more than 1 value.

Pass By Value:

  1. In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
  2. Different memory locations will be created for both variables.
  3. Here there will be a temporary variable created in the function stack that does not affect the original variable.

In the case of pass-by value, the change in the sub-function will not cause any change in the main function whereas in pass-by-reference the change in the sub-function will change the value in the main function.

Pass by value sends a COPY of the data stored in the variable you specify, pass by reference sends a direct link to the variable itself. So if you pass a variable by reference and then change the variable inside the block you passed it into, the original variable will be changed. If you simply pass by the value, the original variable will not be able to be changed by the block you passed it into but you will get a copy of whatever it contained at the time of the call.

Support Faryal's Cusine


What are AOS in AX & D365FO

 

AOS in AX & D365FO


The Microsoft Dynamics AX / D365FO (Finance & Operations) Object Server (AOS) is the second-tier application server in the Microsoft Dynamics AX three-tier architecture.

The AX 2012 3-tier environment is divided as follows:

  1. First Tier – Intelligent Client
  2. Second Tier – AOS
  3. Third Tier – Database Server

In D365FO N-tier environment is divided as follows:

  1. X-Tier – AOS, and Batch servers
  2. X-Tier – Database Server 

In an N-tier solution, the database runs on a server as the X tier; the AOS handles the business logic, Batch jobs/ background process in multiple tiers, and handles the user interface and necessary program logic.

Support Faryal's Cusine


What is AOT in AX & D365FO

 


Define AOT in AX & D365FO



The Application Object Tree (AOT) is a tree view of all the application objects within Microsoft Dynamics AX and D365FO. The AOT contains everything you need to customize the look and functionality of a Microsoft Dynamics AX application.

In the D365FO,  You can find the AOT objects in Application Explorer.

Support Faryal's Cusine


Virtual Company

 

Why We Use Virtual Companies?



Virtual company accounts contain data in certain tables that are shared by any number of company accounts. This allows users to post information in one company that will be available to another company.

Support Faryal's Cusine


D365FO Interview Question

 

D365FO Interview Questions & Answers









What is Microsoft Dynamics AX?

Answer: Link

What is the difference between Microsoft Dynamics AX2012 & D365FO?

Answer: Link

Difference Between Edit And Display Method?

Answer: Link

What Is An Index?

Answer: Link

What are OOPS concepts?

Answer: Following are the main concept of OOPS:

  • Data Abstraction: Showing only the essential information and hide background details.
  • Encapsulation: Wrapping of data member and method to a single unit.
  • Inheritance:-The Flowing of property of parent class to the child class.
  • Polymorphism:-The property of using the same method again and again to perform different things.

Differentiate Refresh (), Reread (), Research (), Executequery ()?

Answer: Link

Why We Use Virtual Companies?

Answer: Link

What is AOT in AX & D365FO?

Answer: Link

What is AOS in AX & D365FO?

Answer: Link

Interface VS Abstract?

Answer: Link

How many types of key tables has?

Answer: Link
  • Replacement Key
  • Alternate key
  • Surrogate key

What is the purpose of the User Interface Builder Class?

Answer: Link

Overloading vs Overriding?

Answer: Link

What is the concept of Extension?

Answer: Link

Define Recordset Operations and types.

Answer: Link

We have 3 types of Bulk Operations
  • insert_recordset
  • update_recordset
  • delete_from

Which development environment is used in D365FO?

Answer: Visual Studio IDE.

What is ConView()?
Answer: It is a Global class that can be utilized to view elements in a tree format.

What is COC (Chain of Command)?

Answer: In D365, To create the extension of the Protected access specified class, We mainly used COC, COC can also be used for a public class. For extension, we used the keyword Extension of(). We use the keyword final to define the class. we use the keyword next to call the base class methods.

Difference between COC and Event Handler?

Answer Link

Why are that people prefer TempDB over InMemory tables while using them in queries for reports?

Answer: Despite both being temporary type tables.

TempDB
You can use TempDB Table the SSRS report with a large amount of data without losing performance.
TempDB tables can be used in Joins with the other temp table or regular table.

Memory Table
Slow performance with a huge number of records.
couldn't use the inMemory table in the query with a join.

How to update the cross-reference tool?

Answer: Link

What is a model in Dynamics 365 Finance & Operations?

Answer: A model is a design-time concept, for example, a warehouse management model or a project accounting model. A model always belongs to a package. A package is a deployment and compilation unit of one or more models. It includes model metadata, binaries, and other associated resources.


What is the difference between package and model in d365?

Answer: A model is a group of elements, such as metadata and source files, that typically constitute a distributable software solution and includes customizations of an existing solution.

A package is a deployment and compilation unit of one or more models. It includes model metadata, binaries, and other associated resources.


What is Extensible Data Security?

Answer: Link

What is the Sysoperation framework how it is different from the runbase framework?

Answer: Link

What is the difference between the configuration key & the security key?

Answer: Link

What is an intermediate language?

Answer Link

How to Import & Export Model?

Answer: Link

How to Import & Export Project?
Answer: Link

What is Microsoft LCS?
Lifecycle Services (LCS) for Microsoft Dynamics is a collaboration portal that provides an environment and a set of regularly updated services that can help you manage the application lifecycle of your implementations of the Dynamics 365 Finance and Operations apps.

Difference between List, set, container and Map?
Answer: Link


Support Faryal's Cusine


What Is An Index?

 


What Is An Index?



A SQL index is used to retrieve data from a database very fast. Indexing a table or view is, without a doubt, one of the best ways to improve the performance of queries and applications.

A SQL index is a quick lookup table for finding records users need to search frequently. An index is small, fast, and optimized for quick lookups. It is very useful for connecting relational tables and searching large tables.

SQL indexes are primarily a performance tool, so they really apply if a database gets large. SQL Server supports several types of indexes but one of the most common types is the clustered index. This type of index is automatically created with a primary key. 

Support Faryal's Cusine


Compnay Currency X++



Company Currency X++



You can find the company Currency using below Code.

CompanyInfo::standardCurrency() 
Ledger::accountingCurrency(CompanyInfo::current()

info(strFmt("%1",CompanyInfo::standardCurrency() ));

info(strFmt("%1",Ledger::accountingCurrency(CompanyInfo::current())));

Support Faryal's Cusine


Pass field value from SalesTable to CustTrans in AX 2012 & D365FO



Pass field value from SalesTable to CustTrans in AX 2012 & D365FO


AX 2012 

Following are the steps to pass the value from Sales Table to custtrans.

1) Create a new field (If not already existing)

2) Create the parm method for that field on CustVoucher class

3) Assign value to this parm method in SalesInvoiceJournalPost.postCustVend() method by using the salesTable buffer

4) Add the code for assigning the variable value(or the parm method value) in CustVoucher.initCustVendTrans() method

And now post an invoice and go to custTrans table to check the field value.

Source AX-2012

D365FO

Add the field in SalesTable 
Add the field in CustTrans
Create Extension class of SalesInvoiceJournalPost
Override postCustVend method using coc 

[ExtensionOf(classStr(SalesInvoiceJournalPost))]
final class SLD_SalesInvoiceJournalPost_Extension
{
    /// <summary>
    ///   Performs the customer related postings.
    /// </summary>
    protected void postCustVend()
    {
        CustTrans                   custTrans;
        Name                        ecomMethodOfPayment = this.salesTable.SLDTenderTypeName;        // getting E-Com method of payment from Sales order

        next postCustVend();

        // getting the customer transaction
        custTrans                   = CustTrans::findByVoucher(this.custInvoiceJour.LedgerVoucher);
        custTrans.selectForUpdate(true);

        // updating the customer transaction
        ttsbegin;
        custTrans.SLDTenderTypeName = ecomMethodOfPayment;
        custTrans.update();
        ttscommit;
    }
}

Please feel free to contact me if you are facing any issue during implementation of this blog.


Support Faryal's Cusine


List of Tables X++ D365FO, AX7 and AX2012


List of Tables X++ D365FO, AX7 and AX2012




       public void run()
    {
        Dictionary dict = new Dictionary();
        DictTable dictTable;


        SysDictTable sysDictTable;
        for (int i=1; i<=dict.tableCnt(); i++)
        {

            sysDictTable=new SysDictTable(dict.tableCnt2Id(i));


        }
    }

Support Faryal's Cusine


Container Functions D365FO-AX 2012

Container Functions D365FO-AX 2012


Today, I am Sharing the functions of container, I have explored during in my career.


Container View

conView


Parameters

cconView(container,Caption,false);


reference screenshot



Insert in container



conIns


Parameters

conIns(container,position,anytype of value);

Example

   container   objContainer;
    int     position=1;
    // insert in container
   objContainer =conIns(objContainer,position,"Sohail Sheikh");

reference screenshot




Length of container 


conLen


Parameters

conLen(containerobject); // will return int

 Example

 container   objContainer=["Sohail Sheikh"];
    int     position=1,len=0;
    

 // container length   
   len=conLen(objContainer);
    info(strFmt("%1",len));

reference screenshot

Pull Data from container


conpeek


Parameters


conpeek(container,position)// will return anytype

Example
  container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        
    // pull data from container   
    objValue=conPeek(objContainer,position);
        info(strFmt("%1",objValue));
 
reference screenshot




Replace Data of container

conpoke

Parameters

conPoke(container,position,anyvalue)// will return container

Example
   container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        
    
     objContainer=conPoke(objContainer,position,"Sheikh Sohail Hussain");
    objValue=conPeek(objContainer,position);    
    info(strFmt("%1",objValue));

reference screenshot



Container Insert Operator 



Parameters


Example
    container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        // insert using operator 
    objContainer+="Inserted";
       
    

    info(strFmt("%1,%2",conPeek(objContainer,1),conPeek(objContainer,2)));

reference screenshot




Find value in Container  

conFind


Parameters

conFind(container,anytype)// will return true or false


Example
 container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        // insert using operator 
    objContainer+="Inserted";
    
      if(conFind(objContainer,"Inserted"))
    {
        info("Value found");
    }

   
reference screenshot





Delete value in Container  

conDel


Parameters

conDel(container,startPosition,EndPosition)// will return container

Example
container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        // insert using operator 
    objContainer+="Inserted";
    
    info(strFmt("Container length Before delete %1",conLen(objContainer)));
    objContainer=conDel(objContainer,2,2);
  
   
   info(strFmt("Container length After delete %1",conLen(objContainer)));

    
reference screenshot





Container  to Str

con2Str


Parameters

conStr(container)// string

Example

  container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        // insert using operator 
    objContainer+="Inserted";
    
    info(con2Str(objContainer));

reference screenshot




Container  Null

conNull


Parameters
conNull()// set the container null

Example
 container   objContainer=["Sohail Sheikh"];
    int     position=1;
    str objValue;

        // insert using operator 
    objContainer+="Inserted";
    
    info(strFmt("Container length Before set null %1",conLen(objContainer)));

 objContainer=conNull(); 
   

   info(strFmt("Container length After set null %1",conLen(objContainer)));


reference screenshot



Str to container

str2con


Parameters

str2Con(stringValues,separator);// will return container

 str objValue;
    container   objContainer;
    objContainer=str2con("Sheikh,Sohail",",");
    
    info(strFmt("%1",con2Str(objContainer)));



reference screenshot



Support Faryal's Cusine


Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...