Blog

Name is Anant Dubey and the intent to create this blog is to discuss the problems and issues that developer face in the dynamics AX development and to share the new things that come up with the new version of AX.

Tuesday, August 31, 2021

How to get value of FormReferenceGroupControl in d365 fo

 


It should be as simple as calling the value() method on the FormReferenceGroupControl object to get the underlying Reference value (int64) which is the RecId of the underlying datasource. For example:

FormReferenceGroupControl referenceGroupControl;

referenceGroupControl = element.control(element.controlId(formControlStr(ReferenceGroupTestingForm, ReviewHeaderInfo_CustomsRepRefGroup))) as FormReferenceGroupControl;

referenceGroupControl.value(); //returns the RecId of the DirPerson table displayed.

To get the Display value which is substituted to the user instead of the underlying RecId value stored in the database, do this:

FormReferenceGroupControl referenceGroupControl;

referenceGroupControl = element.control(element.controlId(formControlStr(ReferenceGroupTestingForm, ReviewHeaderInfo_CustomsRepRefGroup))) as FormReferenceGroupControl;

//this gets the string control that is substituted in for the reference value/recid and displayed to the user. This is the second underlined control in the picture below. This control is determined by the ReferenceGroupControl property "Replacement Field Group" 
//Could be a different type of control than a String control depending on your scenario
FormStringControl subStringControl = referenceGroupControl.controlNum(1) as FormStringControl;

subStringControl.text(); //for string controls, text will contain the display value

enter image description here

One last thing to note is that I believe it is possible to get the values by manipulating datasource objects instead of formcontrol objects. I have seen solutions like this in the past while hunting through google search results.


ref link - https://stackoverflow.com/questions/57508423/how-to-get-value-of-formreferencegroupcontrol

Thursday, August 26, 2021

Financial Dimension Lookup in UI Builder in d365 fo


class SampleReportUIBuilder extends SrsReportDataContractUIBuilder

{

    private DialogField vendordf,dialogbranch;

    

    SampleReportContract     contract;


}

    public void postBuild()

    {

        super();


        contract = this.dataContractObject();


        // binding dialogs with contract fields


        vendordf = this.bindInfo().getDialogField(this.dataContractObject(),

            methodStr(SampleReportContract, parmFinDimProject));

        //dialogbranch = this.bindInfo().getDialogField(this.dataContractObject(),

        //    methodStr(SampleReportContract, parmOMOperatingUnitNumber));


        //dialogbranch.registerOverrideMethod(methodStr(FormStringControl,lookup),methodStr(BEHCMReviewUIBuilder,divisionCodeLookup),this);


  

        vendordf.registerOverrideMethod(methodStr(FormStringControl,lookup),methodStr(SampleReportUIBuilder,PerfPeriodIdLookup),this);

       

    }

    /*

    private void PerfPeriodIdLookup(FormStringControl divisionCodeLookup)

    {

        Query                       query = new Query();

        QueryBuildDataSource        qbd, qbdPerson;

        QueryBuildDataSource        qbds;

        QueryBuildDataSource        qbdsJoin;

        QueryBuildRange             qbr;


        SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(DimensionAttributeLevelValueAllView), divisionCodeLookup);

        qbds= query.addDataSource(tableNum(DimensionAttributeLevelValueAllView));


        qbdsJoin = qbds.addDataSource(tableNum(DimensionAttribute));

        qbdsjoin.relations(true);


        qbr = qbds.addRange(fieldNum(DimensionAttribute,Name));

        qbr.value(queryValue('Project'));


        sysTableLookup.parmQuery(query);

        sysTableLookup.addLookupfield(fieldNum(DimensionAttributeLevelValueAllView, DISPLAYVALUE), true);

     

        sysTableLookup.parmQuery(query);

        sysTableLookup.parmUseLookupValue(False);

        sysTableLookup.performFormLookup();

    }

    */

    private void PerfPeriodIdLookup(FormStringControl _formStringControl)

    {

        DimensionAttribute          DimensionAttribute = DimensionAttribute::findByName('Project');

        Query                       query = new Query();

        QueryBuildDataSource        qbdsFinancialTag,qbdsDirCategory;

        QueryBuildRange             qbr;

        SysTableLookup              SysTableLookup = SysTableLookup::newParameters(tableNum(DimensionFinancialTag),_formStringControl);

   

   

        qbdsFinancialTag = query.addDataSource(tableNum(DimensionFinancialTag));

        qbdsFinancialTag.addOrderByField(fieldNum(DimensionFinancialTag,Value),SortOrder::Ascending);

   

        qbdsDirCategory = qbdsFinancialTag.addDataSource(tableNum(DimensionAttributeDirCategory));

        qbdsDirCategory.relations(false);

        qbdsDirCategory.addLink(fieldNum(DimensionFinancialTag,FinancialTagCategory),fieldNum(DimensionAttributeDirCategory,DirCategory));

   

        qbr = qbdsDirCategory.addRange(fieldNum(DimensionAttributeDirCategory,DimensionAttribute));

        qbr.value(queryValue(DimensionAttribute.RecId));

   

        SysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag,Value));

        SysTableLookup.addLookupfield(fieldNum(DimensionFinancialTag,Description));

        SysTableLookup.addSelectionField(fieldNum(DimensionFinancialTag,Value));

   

        SysTableLookup.parmQuery(query);

        SysTableLookup.performFormLookup();

    }


Wednesday, August 18, 2021

Call Custom Report Design using PrintMgmtDocType Event Handler in d365 FO

Call Custom Report Design in d365 FO 


class PrintMgmtDelegatesHandler  

 {  
   /// <summary>  
   /// Delegate handler for the getDefaultReportFormatDelegate method of the <c>PrintMgmtDocType</c> class.  
   /// </summary>  
   /// <param name = "_docType"><c>PrintMgmtDocumentType</c> enumeration value.</param>  
   /// <param name = "_result">The <c>EventHandlerResult</c> object.</param>  
   [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]  
   public static void getDefaultReportFormatDelegateHandler(PrintMgmtDocumentType _docType, EventHandlerResult _result)  
   {  
     PrintMgmtReportFormatName formatName = PrintMgmtDelegatesHandler::getDefaultReportFormat(_docType);  
     if (formatName)  
     {  
       _result.result(formatName);  
     }  
   }  
   /// <summary>  
   /// Gets the report format value.  
   /// </summary>  
   /// <param name = "_docType">The <c>PrintMgmtDocumentType</c> enumeration value.</param>  
   /// <returns>The report format value.</returns>  
   private static PrintMgmtReportFormatName getDefaultReportFormat(PrintMgmtDocumentType _docType)  
   {  
     switch (_docType)  
     {  
       case PrintMgmtDocumentType::PurchaseOrderRequisition:  
         return ssrsReportStr(PurchPurchaseOrderCopy, Report);  
       case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest:  
         return ssrsReportStr(PurchPurchaseOrderCopy, Report);  
     }  
     return '';  
   }  
 }  

Reference : - https://msdax.wordpress.com/2018/03/16/dynamics-ax-365-ssrs-how-to-call-new-report-design-for-existing-print-management-report/

Sunday, August 1, 2021

Thursday, July 29, 2021

Get Calculate Retail Sales Price in ax2012

 

static void demo_CRT_GetSalesPrice(Args _args)
{
    //To test this code, use the AX 2012 R3 CU8, and use the USRT company
    Microsoft.Dynamics.Commerce.Runtime.Data.IPricingDataManagerV2                pricingManager;
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters priceParameters;
    Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine                       crtSalesLine;
    Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction                crtSalesTransaction;
    System.Object                                                                 roundingRule, currencyConverter;
    CLRObject                                                                     clrSalesLines, enumeratorSalesLine;
    CLRObject                                                                     clrObjectSalesLines;
    System.DateTimeOffset                                                         activeDateTimeOffset;
    System.String                                                                 lineIdString;
    System.String                                                                 customerPriceGroup = "";
    Price                                                                         price;
    Qty                                                                           qty;
    InventDim                                                                     inventdim;
 
    RetailStoreTable    storeTable = RetailStoreTable::find("HOUSTON");   //Lets use houston as an example here
    RetailChannelRecId  channelId = storeTable.RecId;                     //This is the recid for a retail channel. A retail store is an extension of a retail channel.
    CurrencyCode        currencyCode = storeTable.Currency;
    appl.setDefaultCompany(storeTable.company(), false);                  //Setting default company to houstons company
 
    //Creating a unique line ID
    lineIdString = System.Guid::NewGuid().toString();
 
    InventDim.InventLocationId = storeTable.inventLocation;
    InventDim.InventSiteId     = InventLocation::find(storeTable.inventLocation).InventSiteId;
    InventDim                  = InventDim::findOrCreate(InventDim);
 
    //Pricing manager : Encapsulates data access to pricing information.
    pricingManager          = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.AxPricingDataManager::BuildDataManager(channelId);
 
    //Price parameters : types of AX discounts (aka trade agreement discounts, aka not Retail Periodic Discounts) are currently activated and should be allowed on the transaction
    priceParameters         = Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.DiscountParameters::CreateAndInitialize(pricingManager);
    roundingRule            = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetRoundingMethod(currencyCode);
    currencyConverter       = Microsoft.Dynamics.Commerce.Headquarters.RetailProxy.ServiceHelpers::GetCurrencyConverter(currencyCode);
    activeDateTimeOffset    = RetailPricingEngineHelper::getSessionDateTimeInChannelTimeZone(channelId);
 
    //Next we create a crtSalesLine, that represents a channel agnostic sales line.
    crtSalesLine = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesLine();
 
    crtSalesLine.set_ItemId("0001");        //Lets use product 0001 as our example
    crtSalesLine.set_InventoryDimensionId(InventDim.inventDimId);
    crtSalesLine.set_Quantity(10);          //Lets use quantity 10 as our example
    crtSalesLine.set_LineId(lineIdString);  //Let give this line a uniqe ID
 
    crtSalesLine.set_UnitOfMeasureSymbol("ea"); //Let use 'ea' as the unit
 
    //We then create a sales transaction, and add the salesline to this.
    crtSalesTransaction = new Microsoft.Dynamics.Commerce.Runtime.DataModel.SalesTransaction();
    clrObjectSalesLines = crtSalesTransaction.get_SalesLines();
    clrObjectSalesLines.Add(crtSalesLine);                      //This is where the we add the salesLine to the sales transaction
 
    //Lets calculate the prices
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculatePricesForTransaction(
        crtSalesTransaction,
        pricingManager,
        roundingRule,
        currencyConverter,
        customerPriceGroup,
        currencyCode,
        false,
        activeDateTimeOffset);
 
    //Lets calculate the discounts
    Microsoft.Dynamics.Commerce.Runtime.Services.PricingEngine.PricingEngine::CalculateDiscountsForLines(
        pricingManager,
        crtSalesTransaction,
        roundingRule,
        currencyConverter,
        currencyCode,
        '',
        '',
        '',
        true,
        Microsoft.Dynamics.Commerce.Runtime.DataModel.DiscountCalculationMode::CalculateAll,
        activeDateTimeOffset);
 
    //And, let's show what the CRT can give us.
    qty   = crtSalesLine.get_Quantity();
    Price = crtSalesLine.get_Price();
    info(strFmt("Normal sales price is %1 when buying %2", price, qty ));
 
    Price = crtSalesLine.get_DiscountAmount();
    info(strFmt("Discount amount pr unit is %1, when buying %2", price/qty, qty ));
 
    Price = crtSalesLine.get_NetAmountPerUnit();
    info(strFmt("Net amount pr unit is %1, when buying %2", price, qty ));
 
    Price = crtSalesLine.get_TotalAmount();
 
    info(strFmt("Total amount is %1 when buying %2", price, qty ));
}


Reference :- Thanks Mr. Kurt Hatlevik for sharing knowledge
https://kurthatlevik.com/2015/05/21/dax2012-r3-playing-with-retail-crt/