Friday, October 26, 2018

Accessing global cache value and changing logic in same scope based on cache captured in Dynamics 365 for finance and operations

Scope:
Accessing global cache value in one scope (Alternate way for context instance)

Requirement: Without overlay
End user wants to print purchase order confirmation report with new menu item in PO confirmation journal, when user printing report from new menu item it has to print data for particular fields from different ISV solution.

Solution:
There are some possibility in dynamics 365 for finance and operations
1. Context
2. SysGlobalObjectCache
3. Duplicate SSRS report, DP class and controller class (Time consuming task)

2. SysGlobalObjectCache
/// <summary>
/// PurchPurchaseOrderController - Extension cls
/// </summary>
[ExtensionOf(classStr(PurchPurchaseOrderController))]
final class PurchPurchaseOrderController_Extension
{
    /// <summary>
    /// PurchPurchaseOrderController Method Main COC- Extension cLS
    /// </summary>
    /// <param name = "_args">
    /// caller args record
    /// </param>
    public static void main(Args _args)
    {
        SysGlobalObjectCache    PurchGlobalCache =  new SysGlobalObjectCache();

        PurchGlobalCache.remove("PurchPurchaseOrderController",["Report_GlobalParm"]);
        if (_args.menuItemName() == menuItemOutputStr(Cls_PurchPurchaseOrder))
        {
            PurchGlobalCache.insert("PurchPurchaseOrderController",["Report_GlobalParm"], ["Cls_PurchPurchaseOrder"]);
        }
        next main(_args);       
    }

}

//Note: Adding global cache, when its get call from new menu item.

//Note: In DP class, when system having cache in global for the particular transaction scope. then we can differentiate business logic according to that

/// <summary>
/// PurchPurchaseOrderDP - Extension cls
/// </summary>
[extensionof(classstr(PurchPurchaseOrderDP))]
final class PurchPurchaseOrderDP_Extension
{
    /// <summary>
    /// Insert the order header - COC method
    /// </summary>
    /// <param name = "_purchaseOrderHeader">
    /// A <c>PurchPurchaseOrderHeader</c> record to insert.
    /// </param>
    protected void insertOrderHeader(PurchPurchaseOrderHeader _purchaseOrderHeader)
    {
        SysGlobalObjectCache    PurchGlobalCache =  new SysGlobalObjectCache();
        container callerPurchMenu = PurchGlobalCache.find("PurchPurchaseOrderController",["Report_GlobalParm"]);
        if(callerPurchMenu)
        {
            //TODO- Your business logic
        }
        next insertOrderHeader(_purchaseOrderHeader);

        PurchGlobalCache.remove("PurchPurchaseOrderController",["Report_GlobalParm"]); // it should be remove
    }

}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...