5 Dec 2019

Create number sequence in D365 FO

  1. Create the data type.
  2. Add code in the loadModule method of the appropriate NumberSeqModule subclass.
  3. Add a method to the module’s parameters table that returns a reference to the number sequence.
To create the number sequence, we need to extend the loadModule method of the appropriate NumberSeqModule subclass. For example, if we wish to add the number sequence to Accounts Receivable, we will use NumberSeqModuleCustomer. Using chain of command, we extend this class with a new class like the following.

[ExtensionOf(classStr(NumberSeqModuleCustomer))]
final class NumberSeqModuleCustomer_Extension

    protected void loadModule()
    {
        next loadModule();
     
        NumberSeqDatatype datatype = NumberSeqDatatype::construct();

        datatype.parmDatatypeId(extendedTypeNum(CustomerChargesID));
        datatype.parmReferenceHelp("Cusromer Charges NumSeq");
        datatype.parmWizardIsContinuous(false);
        datatype.parmWizardIsManual(NoYes::No);
        datatype.parmWizardIsChangeDownAllowed(NoYes::No);
        datatype.parmWizardIsChangeUpAllowed(NoYes::No);
        datatype.parmWizardHighest(999999);
        datatype.parmSortField(151);
        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);

        this.create(datatype);
    }

}

The last step is to add a method that returns a reference to the number sequence. The best practice is to put the method on the module’s parameters table. Like the NumberSeqModule class, we need to extend the table’s class. This code should look like the following.

[ExtensionOf(tableStr(CustParameters))]
final class ARDCustparameters_Extension
{
    public static NumberSequenceReference numRefCustomerChargesID()
    {
        return NumberSeqReference::findReference(extendedTypeNum(CustomerChargesID));
    }


}

Like the NumberSeqModule subclass, the name of the class needs to end with “Extension” and to use the ExtensionOf attribute (be careful to not use classStr instead of tableStr ). There does not need to be a next statement as this is a new method.

class GenerateCustChargeIDNumberSequence
{        
   
    public static void main(Args _args)
    {     
        NumberSeqModuleCustomer module = new NumberSeqModuleCustomer();
        module.load();

        info('Number Sequence Loaded');
    }


}

3 Dec 2018

Import project dimensions through CSV in AX 2012

static void Explorer_UpdateProjDim(Args _args)
{
    container           readCon;
    Dialog              dialog;
    DialogField         dialogField;
    FileName            fileName;
    Struct              struct;
    ProjId              projId;
    ProjTable           projTable;
    container           ledgerDimension;
    CommaTextIO         commaIO;
    int                 i, records;
    #File

    #file
    dialog = new Dialog ("Select Project Master CSV File");
    dialogField = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(['*.CSV']);
    if (dialog.run())
    {
        fileName = dialogField.value();
        if(!filename)
        {
            throw error('Filename must be filled');
        }
    }

    commaIO = new CommaTextIo(fileName, 'r');
    commaIO.inFieldDelimiter(',');
    readCon = commaIO.read();
    if (commaIO)
    {
        ttsBegin;
        while (commaIO.status() == IO_Status::ok)
        {
            readCon = commaIO.read();

            if (readCon)
            {
                projId = conPeek(readCon, 1);
                struct = new Struct();

                struct.add('Brand', conPeek(readCon, 2)); // specify dimensions
                struct.add('Client', conPeek(readCon, 3)); // specify dimensions
                struct.add('MasterClient', conPeek(readCon, 4)); // specify dimensions
                struct.add('Product', conPeek(readCon, 5)); // specify dimensions

                ledgerDimension = conNull();
                ledgerDimension += struct.fields();
                for (i = 1; i <= struct.fields(); i++)
                {
                    ledgerDimension += struct.fieldName(i);
                    ledgerDimension += struct.valueIndex(i);
                }

                projTable = projTable::find(projId, true);
                if(projTable)
                {
                    projTable.DefaultDimension = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
                    if(projTable.validateWrite())
                    {
                        projTable.update();
                        records++;
                    }
                }
                else
                {
                    error(strFmt("Projid:%1 not exists", projId));
                }
           }
       }
       ttsCommit;
    }
    info(strFmt("%1 records Updated", records));
}

13 Nov 2018

Export customer address with LocationID to Excel Through code in AX 2012

static void AXAPTAEXP_ExportCustomerAddress(Args _args)
{
    #file
    CustTable               custTable;
    DirPartyTable           dirPartyTable;
    DirPartyLocation        dirPartyLocation;
    LogisticsLocation       logisticsLocation;
    LogisticsPostalAddress  logisticsPostalAddress;
    SysExcelApplication     application;
    SysExcelWorkbooks       workbooks;
    SysExcelWorkbook        workbook;
    SysExcelWorksheets      worksheets;
    SysExcelWorksheet       worksheet;
    SysExcelCells           cells;
    SysExcelCell            cell;
    SysExcelFont            font;
    int                     row;
    LogisticsPostalAddressView      view;
    fileName                fileName = "D:\\ address Export\\CustAddress.xlsx";
    FileIoPermission        filepermission;

    // intializing classes to export excel
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');

    if (WINAPI::fileExists(fileName))
    {
        WINAPI::deleteFile(fileName);
    }

    // Setting Header values
    cell = cells.item(1, 1);
    cell.value("AccountNum ");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 2);
    cell.value("LocationID");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 3);
    cell.value("Name ");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 4);
    cell.value("Address");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 5);
    cell.value("State ");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 6);
    cell.value("City");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 7);   
    cell.value("CountryRegionId ");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 8);
    cell.value("Street");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 9);
    cell.value("County ");
    font = cell.font();
    font.bold(true);

    cell = cells.item(1, 10);
    cell.value("ZipCode");
    font = cell.font();
    font.bold(true);
    row = 1;

    // inserting data row wise
    while select AccountNum, Party from custTable
            join RecId from dirPartyTable
                    where   dirPartyTable.RecId == custTable.Party
            join Location, Party from dirPartyLocation
                    where   dirPartyLocation.Party == custTable.Party
            join RecId, Description, LocationID from logisticsLocation
                    where   logisticsLocation.RecId == dirPartyLocation.Location
                join logisticsPostalAddress
                     where   logisticsPostalAddress.Location == logisticsLocation.RecId
    {
        LogisticsPostalAddress = LogisticsPostalAddress::findByLocation(LogisticsLocation::findByLocationId(logisticsLocation.LocationID).RecId);
        row++;
        cell = cells.item(row, 1);
        cell.value(any2str(custTable.AccountNum));
        cell = cells.item(row, 2);
        cell.value(any2str(logisticsLocation.LocationId));
        cell = cells.item(row, 3);
        cell.value(any2str(logisticsLocation.Description));
        cell = cells.item(row, 4);
        cell.value(any2str(LogisticsPostalAddress.Address));
        cell = cells.item(row, 5);
        cell.value(any2str(LogisticsPostalAddress.State));
        cell = cells.item(row, 6);
        cell.value(any2str(LogisticsPostalAddress.City));
        cell = cells.item(row, 7);
        cell.value(any2str(LogisticsPostalAddress.CountryRegionId));
        cell = cells.item(row, 8);
        cell.value(any2str(LogisticsPostalAddress.Street));
        cell = cells.item(row, 9);
        cell.value(any2str(LogisticsPostalAddress.County));
        cell = cells.item(row, 10);
        cell.value(any2str(LogisticsPostalAddress.ZipCode));
    }
    application.displayAlerts(false);
    worksheet.columns().autoFit();
    workbook.saveAs(fileName);
    workbook.comObject().save();
    workbook.saved(true);
    application.quit();

    info(strFmt("File saved in %1", fileName));
}

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...