Friday 17 August 2018

How to Use AX Form As lookup in Dynamics Ax 2012

Consider a scenario where, I required a StringEditControl and Clicking on Control a lookup is open where the list of Customer of selected Legal Entity are available. And After Selecting required Customer, Customer Id Or AccountNum is return form Lookup form.

For This purpose we have to create form, which will used as look Up.

Create a New form. Name It  “FormCustomerLookUp”
New Form
In Data Source Create and New dataSource Name It CustomerTable and Point to CustTable.

Customer Table As DataSource
Expand the Design node  and Right Click on It and Add Grid, Now from CustomerTable Data Source, Drag and drop “AccountNum” and “Party” on Grid. It will create two String Edit Control on Grid bound with CustomerTable.

CustomerFields
Now Select on “StringEdit:CustomerTable_AccountNum” select Properties. Form Properties window Set Its Auto declaration  property to True.

LookUpFieldAutoProperties
Now expend the Methods Node form and Right click and override the Init method from there and add following line of code there.

    element.selectMode(CustomerTable_AccountNum);

LookUpFormInitialization


Now right click on Design Node and Update following properties.
Width=360
Style=LookUP.
StyleToLookUp



Now Create a form where this lookup will use. For this Article I have to create very simple form with only on stringEdit textbox.
On its Design Right click and create StringEditButton with Name “LookUpTest” and from Its property window Auto Declare Property is set to Yes and lookupButton property to “Always”.

TargetFieldProperties

LookUpFields

Monday 13 August 2018

Modify PrintMgmt Report format table

/// <summary>
/// Allows for the population of the PrintMgmtReportFormat table used for print management.
/// </summary>
/// <remarks>
/// This is a framework class. Customizing this class may cause problems with future upgrades to the software.
/// </remarks>
class CITPrintMgmtReportFormatSubscriber
{
    /// <summary>
    /// Event handler for populating the PrintMgmtReportFormat table.
    /// </summary>
    [SubscribesTo(classstr(PrintMgmtReportFormatPublisher), delegatestr(PrintMgmtReportFormatPublisher, notifyPopulate))]
    public static void notifyPopulate()
    {
        UMAPrintMgmtReportFormatSubscriber::populate();
    }

    /// <summary>
    /// Adds records to the <c>PrintMgmtReportFormat</c> table.
    /// </summary>
    /// <remarks>
    /// New report formats are manually added in this method by a developer.  The method is called before
    /// the <c>PrintMgmtSetupUIMain</c> form opens to ensure the list of available reports is updated.
    /// </remarks>
    public static void populate()
    {
        #PrintMgmtSetup
        #ISOCountryRegionCodes
        int reports = 0;
        int added = 0;
        LogisticsAddressCountryRegionISOCode isoCountryCode = SysCountryRegionCode::countryInfo();
        LogisticsAddressCountryRegionId countryRegionId = SysCountryRegionCode::getCountryRegionIdByIsoCode(isoCountryCode);
        #RusReportFormats


        ttsbegin;
       
       
        UMAPrintMgmtReportFormatSubscriber::add(PrintMgmtDocumentType::SalesOrderPackingSlip, ssrsReportStr(UmaPackingSlip, Wayfair), ssrsReportStr(UmaPackingSlip, Wayfair), countryRegionId, NoYes::Yes, PrintMgmtSSRS::SSRS);
        UMAPrintMgmtReportFormatSubscriber::add(PrintMgmtDocumentType::SalesOrderPackingSlip, ssrsReportStr(UmaPackingSlip, Amazon), ssrsReportStr(UmaPackingSlip, Amazon), countryRegionId, NoYes::Yes, PrintMgmtSSRS::SSRS);

        ttscommit;
    }

    private static boolean add(
            PrintMgmtDocumentType _type,
            PrintMgmtReportFormatName _name,
            PrintMgmtReportFormatDescription _description,
            PrintMgmtReportFormatCountryRegionId _countryRegionId,
            PrintMgmtReportFormatSystem _system
            , PrintMgmtSSRS _ssrs = PrintMgmtSSRS::SSRS
            )
    {
        PrintMgmtReportFormat printMgmtReportFormat;
        boolean isDuplicateFound;
        boolean isSystemFormatWithDifferentDescriptionFound;

        #PrintMgmtSetup

        isSystemFormatWithDifferentDescriptionFound = _system && (select firstOnly RecId from printMgmtReportFormat
            where printMgmtReportFormat.DocumentType == _type
                && printMgmtReportFormat.Description != _description
                && printMgmtReportFormat.System == true).RecId != 0;

        // If the format no longer matches up with the existing system formats, change them all to
        // non-system formats. This ensure existing links / setup will not be broken, but also provides
        // a way for the user to fix the formats.
        if (isSystemFormatWithDifferentDescriptionFound)
        {
            update_recordSet printMgmtReportFormat
                setting System = false
                where printMgmtReportFormat.DocumentType == _type
                    && printMgmtReportFormat.Description != _description
                    && printMgmtReportFormat.System == true;
        }

        isDuplicateFound = (select RecId from printMgmtReportFormat
            where printMgmtReportFormat.DocumentType == _type
                && printMgmtReportFormat.Description == _description
                && printMgmtReportFormat.CountryRegionId == _countryRegionId).RecId != 0;

        if (isDuplicateFound)
        {
            if (isSystemFormatWithDifferentDescriptionFound)
            {
                // We must ensure that the system report always matches the country context
                // of the company. If the the country context has been chagned multiple times
                // such that the report format already exists, we must change it back to system.
                update_recordSet printMgmtReportFormat
                    setting System = true
                    where printMgmtReportFormat.DocumentType == _type
                        && printMgmtReportFormat.Description == _description
                        && printMgmtReportFormat.CountryRegionId == _countryRegionId;
            }
            else
            {
                return false;
            }
        }
        else
        {
            // Add the new format
            printMgmtReportFormat.clear();
            printMgmtReportFormat.DocumentType = _type;
            printMgmtReportFormat.Name = _name;
            printMgmtReportFormat.Description = _description;
            printMgmtReportFormat.CountryRegionId = _countryRegionId;
            printMgmtReportFormat.System = _system;
            printMgmtReportFormat.ssrs = _ssrs;
            printMgmtReportFormat.insert();
        }

        return true;
    }

}

D365 Extending Reports

https://blogs.msdn.microsoft.com/dynamicsaxbi/2017/01/02/customizing-app-suite-reports-using-extensions/

https://stoneridgesoftware.com/customizing-the-check-report-via-extensions-in-dynamics-365-for-operations/


https://blogs.msdn.microsoft.com/dynamicsaxbi/2017/01/01/how-to-custom-designs-for-business-docs/