Wednesday, 17 April 2019

Creating a new number sequence in D365


Carry out the following steps in order to complete this recipe:



1. Create a new NumberSequenceModuleCustomer_packet class in the D365 Project that
extends the NumberSequenceModuleCustomer class in the Application and add the
following code snippet at the bottom of the loadModule_Extension() method:

class NumberSequenceCustomer_packet extends NumberSeqModuleCustomer
{
public void loadModule_Extension()
{
NumberSeqDatatype datatype = NumberSeqDatatype::construct();

datatype.parmDatatypeId(extendedTypeNum(CustomerGroupId));
datatype.parmReferenceHelp("Customer group Id");
datatype.parmWizardIsContinuous(false);
datatype.parmWizardIsManual(NoYes::No);
datatype.parmWizardIsChngeDownAllowed(NoYes::Yes);
datatype.parmWizardIsChngeUpAllowed(NoYes::Yes);
datatype.parmWizardHihest(999999);
datatype.parmSortField(20);
datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
this.create(datatype);
}
}


2. Create a new runnable class (Job) with the following lines of code, build the solution and run it:


class loadNumSeqCustPackt
{
public static void Main(Args args)
{
NumberSeqModuleCustomer_packt nymberSeqMod = new
NumberSeqModuleCustomer_packt();

nymberSeqMod.loadModule_Extension();
}

}

3.  Run the number sequence wizard by clicking on the Generate button under Number sequence by going to Organization administration | Common | Number sequence and then click on the Next button, as shown in the following screenshot:



4.  Click on Details to view more information. Delete everything apart from the rows where Area is Accounts receivable and Reference is Customer group. Note the number sequence codes and click on the Next button, as shown here:


5.  On the last page, click on the Finish button to complete the setup, as shown in the  following screenshot:

6.    The newly created number sequences now can be found in the Number sequence
form, as shown in the following screenshot:
7.    Navigate to Organization administration | Number sequences | Segment configuration and notice the new Customer group reference under the Accounts receivable area:
8.    Navigate to Accounts receivable | Setup | Accounts receivable parameters and select the Number sequences tab. Here, you should see the new number sequence code:

9.    The last thing to be done is to create a helper method for this number sequence. Create a new extension class CustParameters_Extension for the CustParameters table and add it to the Dynamics 365 Project and then create the following method and build the solution:



[ExtensionOf(tableStr(CustParameters))]
Final class CustParameters_Extension
{
 client server static NumberSequenceReference numRefCustGroupId()
{
NumberSequenceReference NumberSeqReference;
NumberSeqReference = NumberSeqReference::findReference (extendedTypeNum(CustGroupId));
return NumberSeqReference;
}
}



How it works...

We start the recipe by adding a number sequence initialization code into the NumberSeqModuleCustomer_packt class. As understood from its name, the number sequence initialization code holds the initialization of the number sequences that belong to the Accounts receivable module.

The code in the loadModule_Extension() method defines the default number sequence settings to be used in the wizard, such as the data type, description, and highest possible number. Additional options such as the starting sequence number, number format, and others can also be added here. All the mentioned options can be changed while running the wizard. The addParameterType() method is used to define the number sequence scope. In the example, we created a separate sequence for each Legal entity.

Before we start the wizard, we initialize number sequence references. This should be done as a part of the Dynamics 365 for Finance and Operations initialization checklist, but in this example, we execute it manually by calling the loadModule_Extension() method of the NumberSeqApplicationModule_packt class.

Next, we execute the wizard that will create the number sequences for us. We skip the welcome page and in the second step of the wizard, the Details button can be used to display more options. The options can also be changed later in the Number sequences form before or even after the number sequence is actually used. The last page shows an overview of what will be created. Once completed, the wizard creates new records in the Number sequences form for each company.

The newly created number sequence reference appears in the Segment configuration form. Here, we can see that the Data area checkbox is checked, which means that we will have separate number lists for each company. The number sequence setup can be normally located in the module parameter forms.

Friday, 12 April 2019

Getting company address based on the purpose

static void CompanyAddress(Args _args)
{
    CompanyInfo companyInfo;
    LogisticsPostalAddress  postalAddress;
    DirPartyLocation partyLocation;
    LogisticsLocationRole   locationRole;
    DirPartyLocationRole    partyLocationRole;

    LogisticsEntityPostalAddressView postalAddressView;

   while select companyInfo
           where companyInfo.DataArea == curext()
        join partyLocation
            where partyLocation.Party == companyInfo.RecId
        join postalAddress
            where postalAddress.Location == partyLocation.Location
        join partyLocationRole
            where partyLocationRole.PartyLocation == partyLocation.RecId
        join locationRole
           where partyLocationRole.LocationRole == locationRole.RecId
            && locationRole.Name == strFmt("%1",logisticsLocationRoleType::Delivery)
    {
        info(strFmt("Purpose: %1, IsPrimary: %2, Address %3",locationRole.Type, partyLocation.IsPrimary,  postalAddress.Address));
    }

}

Get customer or vendor email address based on the purpose

static void Vend_CustEmailAddressUsingPurpose(Args _args)
{
    VendTable                           vendTable; //if you need customer you can change CustTable.
    DirPartyLocation                    dirPartyLocation;
    LogisticsElectronicAddress          logisticsElectronicAddress;
    LogisticsElectronicAddressRole      logisticsElectronicAddressRole;
    LogisticsLocationRole               logisticsLocationRole;
   
    select firstOnly vendTable
        where vendTable.AccountNum == '‪‪‪US-105';
   
    while select dirPartyLocation
        where dirPartyLocation.party == vendTable.Party
    {
        while select logisticsElectronicAddress
            where logisticsElectronicAddress.Location == dirPartyLocation.Location
                && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
        {
            while select logisticsElectronicAddressRole
                where logisticsElectronicAddressRole.ElectronicAddress == logisticsElectronicAddress.RecId
                join logisticsLocationRole
                where logisticsLocationRole.RecId == logisticsElectronicAddressRole.LocationRole
                && logisticsLocationRole.Name == strFmt("%1",logisticsLocationRoleType::Business)
            {
                info(strFmt("%1 - %2", logisticsElectronicAddress.Locator, logisticsLocationRole.Name));
            }
        }
    }
}

output:

Step-by-Step Guide to Restore a SQL BACPAC File - Microsoft dynamics D365 Fin & Ops

 Restore steps for bacpac file in to SQL server - Microsoft dynamics D365 Fin & Ops. Log in to LCS and navigate to the asset library. On...