Tuesday, 15 November 2022

Create and use cache mechanism in D365 F&O using x++

Below class is used to set, get, remove cache from the application

public class ENCGlobalCacheManager

{

    // This string is appended for the values that are containers. Avoids type mismatches

    public static const str cont = "_container";

    private static str getUniqueSessionId()

    {

        return curUserId() + "_" + int2Str(sessionId());

    }

 

    public static anytype get(anytype _key, anytype _returnValue = '')

    {

        return appl.globalCache().get(ENCGlobalCacheManager::getUniqueSessionId(), _key, _returnValue);

    }

 

    public static anytype getContainer(anytype _key, anytype _returnValue = '')

    {

        if(ENCGlobalCacheManager::containerIsSet(_key))

        {

            return appl.globalCache().get(ENCGlobalCacheManager::getUniqueSessionId() + ENCGlobalCacheManager::cont, _key, _returnValue);

        }

        else

        {

            return null;

        }

    }

    public static boolean isSet(anytype _key)

    {

        return appl.globalCache().isSet(ENCGlobalCacheManager::getUniqueSessionId(), _key);

    }

    public static boolean containerIsSet(anytype _key)

    {

        return appl.globalCache().isSet(ENCGlobalCacheManager::getUniqueSessionId() + ENCGlobalCacheManager::cont, _key);

    }

 

    public static boolean remove(anytype _key)

    {

        return appl.globalCache().remove(ENCGlobalCacheManager::getUniqueSessionId(),  _key);

    }

 

    public static boolean removeContainer(anytype _key)

    {

        return appl.globalCache().remove(ENCGlobalCacheManager::getUniqueSessionId() + ENCGlobalCacheManager::cont,  _key);

    }

 

    public static boolean set(anytype _key, anytype _value, boolean _isVolatile = true)

    {

        return appl.globalCache().set(ENCGlobalCacheManager::getUniqueSessionId(), _key, _value, _isVolatile);

    }

 

    public static boolean setContainer(anytype _key, anytype _value, boolean _isVolatile = true)

    {

        return appl.globalCache().set(ENCGlobalCacheManager::getUniqueSessionId() + ENCGlobalCacheManager::cont, _key, _value, _isVolatile);

    } 

} 


How to set value to cache

If (ENCGlobalCacheManager::isSet("KeyValue"))

{

    ENCGlobalCacheManager::remove("KeyValue");

}

ENCGlobalCacheManager::set("KeyValue", "Value");


KeyValue - KeyValue can be anything like salesId, custGroupId

Value    - Actual value to set in cache


How to get value to cache

if(ENCGlobalCacheManager::isSet("KeyValue")

{

    this.Value= ENCGlobalCacheManager::get("KeyValue");

    ENCGlobalCacheManager::remove("KeyValue");

}


Tuesday, 18 January 2022

Export D365 F&O data to Azure Data Lake

Azure Data Lake        

Azure Data Lake is a fully managed, scalable, and highly available service from Microsoft. It includes built-in disaster recovery. 

When you enable the Export to Azure Data Lake add-in, you connect your F&O environment to a designated data lake. Authorized users can then copy data from your F&O environment to that data lake. Tools such as Power BI and Azure Synapse enable analytics, business intelligence, and machine learning scenarios for data in the data lake.



Data that is stored in the data lake is organized in a folder structure that uses Common Data Model format. Common Data Model format provides additional metadata in a machine-readable JavaScript Object Notation (JSON) format, so that downstream tools can determine the semantics of the data. The additional metadata includes the table structure, descriptions, and data types.

  • Model.json
    • Metadata file contains information about entity records/attributes and links to data files















  • Data Files
    • Data files have well-defined structure and format and are references in model.json file
    • Files must be in .csv format without header information
    • Columns defined in model.json
    • CSV files containing the data

Configure Export to Data Lake

Reference :- Source from Microsoft Docs