Showing posts with label Dynamics 365 Finance & Operations. Show all posts
Showing posts with label Dynamics 365 Finance & Operations. Show all posts

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 you can define in a table as if it were a regular data field, but its value is computed on-the-fly based on certain calculations or business logic whenever it is queried. Virtual fields are often used to display derived or computed information without storing it in the database.


Advantages of Virtual Fields:


  • No need to store redundant data in the database.
  • Useful for displaying calculated values without performing calculations every time.

Computed Field:

A computed field in D365FO is similar to a virtual field in that its value is calculated based on certain rules or business logic. However, computed fields are typically defined in the Application Object Tree (AOT) and are often used within forms or reports to display dynamic information based on specific calculations.


Advantages of Computed Fields:

  • Provides dynamic and real-time calculations.
  • Can be used for various display purposes within forms and reports.

In summary, both virtual fields and computed fields are used to display calculated or derived information in Dynamics 365 Finance and Operations. Virtual fields are defined in tables and calculated on-the-fly during queries, while computed fields are often used within forms and reports to display dynamic calculations based on business logic. The choice between them depends on where and how you want to display the calculated information.

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())));
}

Data Management Project Using X++

 

Data Management Project Using X++


Using the following code, you can import the file and execute the project using your x++ code.

In the code, I am making the file on runtime and uploading the file into temp storage for the demo purpose
but you can use the file uploader as per your requirement.


Code

class AD_Test
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        FileUploadTemporaryStorageStrategy fileUploadStrategyInstance;
        DMFDefinitionGroupEntity    definitionGroupEntityBuffer;
        DMFEntity                   dmfEntitybuffer;
        FileUploadTemporaryStorageResult result;
        SysDictClass uploadStrategyDictClassInstance;
        str entityName = 'VendVendorGroupEntity';
        System.IO.StreamWriter swriter;
        System.IO.MemoryStream   fileStream;
        DMFExecutionId executionId;
        #File



        fileStream = new System.IO.MemoryStream();
        swriter = new System.IO.StreamWriter(fileStream);
        swriter.WriteLine("VENDORGROUPID,DESCRIPTION");
        swriter.WriteLine(strFmt("%1,%2",'Ex-VendGroup','Example Vendor group'));
        swriter.Flush();

        uploadStrategyDictClassInstance = new SysDictClass(className2Id('FileUploadTemporaryStorageStrategy'));
        fileUploadStrategyInstance = uploadStrategyDictClassInstance.makeObject() as FileUploadTemporaryStorageStrategy;
        result = fileUploadStrategyInstance.uploadFile(fileStream, 'VendorsGroups.csv');
     
        fileStream.Dispose();

        CodeAccessPermission::revertAssert();

        executionId = DMFUtil::setupNewExecution('ImportVendorGroup');

        select firstonly  Entity from definitionGroupEntityBuffer exists join dmfEntitybuffer
            where definitionGroupEntityBuffer.DefinitionGroup == 'ImportVendorGroup' &&
                dmfEntitybuffer.EntityName == definitionGroupEntityBuffer.Entity &&
            dmfEntitybuffer.TargetEntity == entityName ;

       
        DMFDefinitionGroupExecution executionBuffer = DMFDefinitionGroupExecution::find('ImportVendorGroup', definitionGroupEntityBuffer.Entity, executionId, true);
        ttsbegin;
        executionBuffer.FilePath = result.getFileId();
        executionBuffer.IsTransformed = NoYes::Yes;
        executionBuffer.update();
        ttscommit;

        DMFQuickImportExport::doPGImport('ImportVendorGroup', executionId, true);
    }

}

Existing Index Changes D365FO

 

Change existing Index D365FO

 

As we all have a requirement in the past to perform the changes in the existing indexes, and as we know the customization is not allowed in the OOTB elements, so we couldn’t achieve this.

 

How we can achieve it?

 

In D365FO, we couldn’t delete or disable the existing index, but there is one way to achieve this.

We can disable the index on SQL level by using the SQL script even on prod.

 

Yes, you are reading correct, we can disable the index and it will not enable again during package deployment, please only disable the index not remove the index, otherwise, Microsoft classes will re-create the index during deployment.

 Now you can create the new index as per your requirements and it will work properly and will not make any conflict with the existing index, because it is already in the disabled state.

How you can disable the index?

 

  public void disableIndex(str _tableName, str _indexName)

    {

        str sql;

        Connection conn;

        SqlStatementExecutePermission permission;

        ;

       

            sql= strFmt("ALTER INDEX %1 ON %2 DISABLE;", _ indexName, _tableName);

            // sql = ‘delete from custTable’;

            permission = new SqlStatementExecutePermission(sql);

            conn = new Connection();

            permission = new SqlStatementExecutePermission(sql);

            permission.assert();

            conn.createStatement().executeUpdate(sql);

            // the permissions needs to be reverted back to original condition.

            CodeAccessPermission::revertAssert();

       

    }


Important

Before applying the index, please perform the analysis on your existing data, might possible

you can face the issue.

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...