Tuesday, July 30, 2019

New number sequence in D365

Issue: How to create a new number sequence in D365?

Solution: 1. Create a new EDT for eg. TSTCustomsJourId.
                2. Extend standard "NumberSeqModule" enum and add a new enum value e.g NumberSeqModule::TSTCustoms.
             
Implement below class and methods.

class TSTNumberSeqModuleCustoms extends NumberSeqApplicationModule
{
    /// <summary>
    /// Sets up the references for the <c>TSTCustoms</c> module number sequences.
    /// </summary>
    protected void loadModule()
    {
        NumberSeqDatatype datatype = NumberSeqDatatype::construct();

        /* Setup document numbers */
        datatype.parmDatatypeId(extendedtypenum(TSTCustomsJourId));
        datatype.parmReferenceHelp(literalstr("TST:CustomsHelpText"));
        datatype.parmWizardIsContinuous(false);
        datatype.parmWizardIsManual(NoYes::No);
        datatype.parmWizardfetchAheadQty(10);
        datatype.parmWizardIsChangeDownAllowed(NoYes::No);
        datatype.parmWizardIsChangeUpAllowed(NoYes::No);
        datatype.parmSortField(1);

        datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
        this.create(datatype);
    }

    /// <summary>
    /// Gets the number sequence module that the current object is attached to.
    /// </summary>
    /// <returns>
    /// The number sequence module that the current object is attached to.
    /// </returns>
    public NumberSeqModule numberSeqModule()
    {
        return NumberSeqModule::TSTCustoms;
    }

    /// <summary>
    ///    Appends the current class to the map that links modules to number sequence data type generators.
    /// </summary>
    [SubscribesTo(classstr(NumberSeqGlobal),delegatestr(NumberSeqGlobal, buildModulesMapDelegate))]
    static void buildModulesMapSubsciber(Map numberSeqModuleNamesMap)
    {
        NumberSeqGlobal::addModuleToMap(classnum(TSTNumberSeqModuleCustoms), numberSeqModuleNamesMap);
    }

}

Financial dimensions - default dimension - ledger dimension - D365 - code samples



Get dimension value from defaultDimension:

DimensionAttributeValueSet dimAttrValueSet;
DimensionAttributeValueSetItem dimAttrValueSetItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttribute;


select dimAttrValueSetItem
where dimAttrValueSetItem.DimensionAttributeValueSet == this.defaultDimension
join dimAttrValue
where dimAttrValue.RecId == dimAttrValueSetItem.DimensionAttributeValue
join dimAttribute
where dimAttribute.RecId == dimAttrValue.DimensionAttribute
   && dimAttribute.BackingEntityType == tableNum(DimAttributeOMBusinessUnit);

Return dimAttrValueSetItem.DisplayValue;


Another way:

public static DimensionValue getDimensionValue(RecId defaultDimension, Name dimName)
{
    DimensionAttributeValueSetStorage dimStorage;
    ;
dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);
return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);
}


Get dimension value from a ledger dimension:
select dimensionAttributeLevelValueView
     where dimensionAttributeLevelValueView.ValueCombinationRecId == generalJournalAccountEntry.LedgerDimension
     join dimensionAttribute
where dimensionAttribute.RecId == dimensionAttributeLevelValueView.DimensionAttribute
&& dimensionAttribute.BackingEntityType == tableNum(DimAttributeOMBusinessUnit);

custBalanceTmp.BusinessUnit = dimensionAttributeLevelValueView.DisplayValue;

Get main account from ledger dimension:

mainAccount = MainAccount::findByLedgerDimension(generalJournalAccountEntry.LedgerDimension);


Create ledger dimension using main account and default dimension:

ledgerDimension = LedgerDimensionFacade::serviceCreateLedgerDimension(salesForFreeInvoiceAccount, salesPurchLine.defaultDimension);

How to get all the table names (Standard/Customized) in D365? - solution

Issue: How to get all the table names (Standard/Customized) in D365?

Solution: Below lookup method should be implemented to get the desired lookup.

              /// <summary>
        /// The method will lookup all the table names.
        /// </summary>
        public void lookup()
        {
            Query                   lookupQuery;
            QueryBuildDataSource    qbds;
            SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(SqlDictionary), this);

            // Display the Name field in the lookup form.
            sysTableLookup.addLookupfield(fieldnum(SqlDictionary, Name));

            lookupQuery = new Query();
            qbds = lookupQuery.addDataSource(tablenum(SqlDictionary));
            qbds.addRange(fieldNum(SqlDictionary, fieldId)).value(queryValue(0));
            qbds.addSortField(fieldNum(SqlDictionary, Name), SortOrder::Ascending);
            qbds.addRange(fieldNum(SqlDictionary, shadow)).value(queryValue(0));
            qbds.addRange(fieldNum(SqlDictionary, flags)).value(queryValue(0));

            sysTableLookup.parmQuery(lookupQuery);

            sysTableLookup.performFormLookup();
        }

How to lookup fields of an existing table (Standard/Customized) in D365? - solution

        Issue: How to lookup fields of an existing table (Standard/Customized) in D365?

        Solution: Below code should be implemented to show lookup of existing table(s).

        public void lookup()
        {
            Query                                lookupQuery;
            QueryBuildDataSource    qbds;
            SysTableLookup               sysTableLookup = SysTableLookup::newParameters(tablenum(SqlDictionary), this);

            // Display the Name field in the lookup form.
            sysTableLookup.addLookupfield(fieldnum(SqlDictionary, Name));

            // Create a custom Query
            lookupQuery = new Query();
            qbds = lookupQuery.addDataSource(tablenum(SqlDictionary));
            qbds.addRange(fieldNum(SqlDictionary, fieldId)).value((SysQuery::valueNot(0)));
            qbds.addSortField(fieldNum(SqlDictionary, Name), SortOrder::Ascending);
            qbds.addRange(fieldNum(SqlDictionary, shadow)).value(queryValue(0));
            qbds.addRange(fieldNum(SqlDictionary, flags)).value(queryValue(0));
            qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum("YourTableName")));
         
           // Multiple tables can be added as range, if required
           // qbds.addRange(fieldNum(SqlDictionary, TabId)).value(queryValue(tableNum(InventTable)));

            sysTableLookup.parmQuery(lookupQuery);

            sysTableLookup.performFormLookup();
        }