Showing posts with label Data import in Ax2012. Show all posts
Showing posts with label Data import in Ax2012. Show all posts

Thursday, 23 August 2012

Step by step import with Data Migration Framework - AX 2012


Continuation to my previous article AX 2012 Data Migration Framework

In this article, we are Importing the LedgerGeneraljournal into AX 2012. 

Demo Files are available at:
C:\Program Files\Microsoft Dynamics AX 2012 Data Migration Framework (Beta)\DemoFiles









This is the beta release and therefore there will be bugs, issues and it’s not a complete offering. With that, when we start to look at the use of this framework, we must start with the types of sources we can work from. We do this from the Data Migration Framework > Setup > Source Data Formats. 

Apart from flat file, MS is planning to add Ax and ODBC types to the framework.





We can see that there are plans then for allowing both ODBC source types, as well as enabling AX-to-AX, source-to-target usage of this framework. Since this is file based on source types for the Data Migration Framework, out-of-the-box usage for the framework is limited. It’s powerful, and has a lot of great possible value, specifically when the AX and ODBC types are fully added. DMF is work well with the file sources, as I have tested and imported some of the data. If your source data is in flat files then you can start getting a lot of use from the framework.

1. Click on Data Migration Framework > Setup > Source data formats to set up your source data format.





2. Applications:  you can select your dimensions. The Dimension code lookup is a multiselection lookup (tick the selection box on the left of the lookup and ok).




3. Click on Data Migration Framework > Common > Processing group. Create a new record and give it a name and description



4. From the Processing group form, click on Entities.

Create a new record for the LedgerGeneraljournal. If we are selecting data from demo flat files, select the path in The Sample file path field or else you want to select (modify) the fields then leave The Sample file path field will be blank.




If you use the Demo files, then skip steps 5, 6 and 7. If you want to modify the columns, then do steps 5, 6 and 7, as it will ask you if you want to modify the existing file format.

5. Generate a sample file by clicking on Generate source file button. Follow the wizard and select the fields to import.







6. Then click the Generate sample file button. This will open up the sample file in notepad.
Click Finish when done.

7. Now fill in your data on the txt file.




8. Back on the main form click the Generate source mapping button. This will analyse the file and do the mapping between the file and the stagging table.

9. Now you can open and view the mapping by clicking on the Modify source mapping button.


It should looks something like this. The Source is your txt file and the Staging is your staging table in AX. If 
your source file is messed up, you should be able to see it here.



10. Now validate the setup by clicking the Validate button on the main form.

11. View target mapping. This is a mapping between the Staging to the Target table. This should already be predefined. You can however modify the mapping.


The Function options on the left. These are predefined methods in the class to allow you to execute business logic. The example below, when you pass in a string of dimensions A-B-C, the GenerateDefaultDimension function splits the string up and generates a DefaultDimension RecId.



12. When we check the Entities from, Click the Preview source file button. This loads up the file, to give you a preview of your file.




13. In Processing group form and click the Get staging data. This opens up a dialog with the processing group, click OK. You will then get this form.

Click on the Run to run client side or Click on Run on AOS to run server side. Usually, the user account doing the import wont have access to SQL integration servers. Use the second option and it will run under the service account. This should run and complete with out errors.






14. Now you can see the staging table by going to the Execution history from the Processing group form. From there you click the View staging data button. You can modify the staging data before you process it to the target.






15. To process to the target, click on the Copy data to target button. Follow the options to execute the process.





It’s done, Now the data has been migrated to AX 2012.

That's it for now... :) 



Monday, 23 July 2012

Data import in ax 2012 - Vendor

Vendor import


Inbound port of the vendor service
To call the service, you need to expose the service on a new inbound port in Microsoft Dynamics AX.
1. Click System administration >Setup > Services and Application Integration Framework > Inbound ports, and then click New.
2. Give the new port a name, such as Vendor Services.
3. Enter a description.
4. Under Service Contract Customizations, click Service Operations. The Select service operations form opens.
5. Select the vendVendTableService operations, move them to the Selected operations pane, and then click Close.
6. In the Inbound ports form, click Activate

You can now access the service externally by using the WSDL URI.


CSV:          

Name
MMS Gen Merchants
KnownAs
MMS Gen Merchants
PhoneticName
MMS Gen Merchants
OrganizationName
MMS Gen Merchants
NameAlias
MMS Gen Merchants
CustGroup
IT
SalesGroup

DlvMode

InvoiceAddressType

PostalLocationName
Primary
Postalstreet
Marol Maroshi
PostalBuildingCompliment

PostalPOBox

PostalCity
Mumbai
PostalState
MH
PostalZip
2219099
PostalCountry
IND
PostalRoles
Delivery;Invoice;Business
IsPostalPrimary
Yes
ContactLocationName
Primary Phone
Locator

ContactType
Phone
ContactRoles
Business
IsContactPrimary
yes


Set up the vendor service reference in Visual Studio

1. Open Visual Studio, and create a new project.
2. Add a new service reference by using the WSDL URI for the vendor service from the Inbound ports form.
3. Add a Using statement for the service reference.  





Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Vendors.VendServiceReference;
using System.IO;
using System.Text.RegularExpressions;

namespace Vendors
{
    public partial class Vendor : Form
    {
        internal static int NameIndex = 0;
        internal static int KnownAsIndex = 1;
        internal static int PhoneticNameIndex = 2;
        internal static int OrganizationNameIndex = 3;
        internal static int NameAliasIndex = 4;
        internal static int CustGroupIndex = 5;
        internal static int SalesGroupIndex = 6;
        internal static int DlvModeIndex = 7;
        internal static int InvoiceAddressTypeIndex = 8;
        internal static int PostalLocationNameIndex = 9;
        internal static int PostalstreetIndex = 10;
        internal static int PostalBuildingComplimentIndex = 11;
        internal static int PostalPOBoxIndex = 12;
        internal static int PostalCityIndex = 13;
        internal static int PostalStateIndex = 14;
        internal static int PostalZipIndex = 15;
        internal static int PostalCountryIndex = 16;
        internal static int PostalRolesIndex = 17;
        internal static int IsPostalPrimaryIndex = 18;
        internal static int ContactLocationNameIndex = 19;
        internal static int LocatorIndex = 20;
        internal static int ContactTypeIndex = 21;
        internal static int ContactRolesIndex = 22;
        internal static int IsContactPrimaryIndex = 23;
        internal static int VendAccountNum = 24;
        internal static int VendCurrency = 25;
        internal static int InvoiceAccount = 26;
        internal static int UPSzone = 27;
        internal static int SalestaxGroup = 28;
        internal static int PricesInclSalestax = 29;
        internal static int CalculateWithholdingTax = 30;
        internal static int Warehouse = 31;
        internal static int PurchaseOrderpricesAmount = 32;
        internal static int Fax = 33;
        internal static int Email = 34;
        internal static int TermsofPayment = 35;
        internal static int Methodofpayment = 36;
        internal static int Mobilephone = 37;
        internal static int InternetAddress = 38;

        public Vendor()
        {
            InitializeComponent();
        }
        public static List<string[]> ParseCSVFile(string path, Boolean hasHeaders)
        {
            List<string[]> CSVRows = new List<string[]>();
            int rowNumber = 0;
           using (StreamReader inputFile = new StreamReader(path))
            {
                string line;
                string[] line1;
                while ((line = inputFile.ReadLine()) != null)
                {
                    String pattern = ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))";
                    Regex r = new Regex(pattern);
                    line1 = r.Split(line);
                    if (hasHeaders != true || rowNumber != 0)
                    {
                        CSVRows.Add(line1);
                    }
                    rowNumber++;
                }
            }
            return CSVRows;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //VENDOR MASTER CREATION
            VendTableServiceClient vendSvcClient = new VendTableServiceClient();
            List<string[]> VendData = ParseCSVFile("D:\\Vendors.csv", true);
            foreach (string[] vendor in VendData)
            {
                AxdVendTable AxdVendor = new AxdVendTable(); 
                Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable dirPartyTable = new Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable();
                AxdEntity_VendTable VendTable = new AxdEntity_VendTable();
                AxdEntity_VendTable[] vendorList = new AxdEntity_VendTable[1];
                EntityKey[] entityKey;                Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirOrganization org = new Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirOrganization()
                {
                  KnownAs = vendor[KnownAsIndex],
                    PhoneticName = vendor[PhoneticNameIndex],
                    OrganizationName = new Vendors.VendServiceReference.AxdEntity_OrganizationName[1],
                    NameAlias = vendor[NameAliasIndex],
                    Name = vendor[NameIndex]
                }; 
                Vendors.VendServiceReference.AxdEntity_OrganizationName orgName = new Vendors.VendServiceReference.AxdEntity_OrganizationName()
                {
                    Name = vendor[OrganizationNameIndex]
                };
                //Assign organization name to the base organization.
                org.OrganizationName[0] = orgName;
                //Add an address to the org. You can add a loop and add as many address and types you want to here
                Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView[] postalAddView = new Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView[1];
                postalAddView[0] = new Vendors.VendServiceReference.AxdEntity_DirPartyPostalAddressView()
                {
                    LocationName = vendor[PostalLocationNameIndex],
                    BuildingCompliment = vendor[PostalBuildingComplimentIndex],
                    City = vendor[PostalCityIndex],
                    State = vendor[PostalStateIndex],
                    ZipCode = vendor[PostalZipIndex],
                    Street = vendor[PostalstreetIndex],
                    CountryRegionId = vendor[PostalCountryIndex],
                    Roles = vendor[PostalRolesIndex],
                    IsPrimary =
                    (Vendors.VendServiceReference.AxdExtType_LogisticsIsPrimaryAddress)Enum.Parse(typeof(Vendors.VendServiceReference.AxdExtType_LogisticsIsPrimaryAddress), vendor[IsPostalPrimaryIndex])
                };
                //Add the party Address to the Organization
                org.DirPartyPostalAddressView = postalAddView;
Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView[] contactList = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView[5];
                contactList[0] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
                {
                    LocationName = vendor[ContactLocationNameIndex],
                    Locator = vendor[LocatorIndex],
                    IsPrimarySpecified = true,
                    IsPrimary = (Vendors.VendServiceReference.AxdEnum_NoYes)Enum.Parse(typeof(Vendors.VendServiceReference.AxdEnum_NoYes),
                    vendor[IsContactPrimaryIndex]),
                    TypeSpecified = true,
                    Type = (Vendors.VendServiceReference.AxdEnum_LogisticsElectronicAddressMethodType)Enum.Parse(typeof(Vendors.VendServiceReference.AxdEnum_LogisticsElectronicAddressMethodType), vendor[ContactTypeIndex]),                   
                    Roles = vendor[ContactRolesIndex]
                };
                 contactList[1] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
                {
                    LocationName = "Fax",
                    Locator = vendor[Fax],
                    TypeSpecified = true,
                    Type = AxdEnum_LogisticsElectronicAddressMethodType.Fax,
                    Roles = vendor[ContactRolesIndex]
                };
                contactList[2] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
                {
                    LocationName = "E-mail",
                    Locator = vendor[Email],
TypeSpecified = true,
                    Type = AxdEnum_LogisticsElectronicAddressMethodType.Email,
                    Roles = vendor[ContactRolesIndex]
                };
                contactList[3] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
                {
                    LocationName = "Mobile phone",
                    Locator = vendor[Mobilephone],
                    TypeSpecified = true,
                    Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone,
                    Roles = vendor[ContactRolesIndex]
                };
                contactList[4] = new Vendors.VendServiceReference.AxdEntity_DirPartyContactInfoView()
                {
                    LocationName = "Internet address",
                    Locator = vendor[InternetAddress],
                    TypeSpecified = true,
                    Type = AxdEnum_LogisticsElectronicAddressMethodType.URL,
                    Roles = vendor[ContactRolesIndex]
                }; 
                //Add the contacts to the organization
                org.DirPartyContactInfoView = contactList;
                VendTable.AccountNum = vendor[VendAccountNum];
                VendTable.Currency = vendor[VendCurrency];
                VendTable.VendGroup = vendor[CustGroupIndex];
                VendTable.DlvMode = vendor[DlvModeIndex];
                VendTable.InvoiceAccount = vendor[InvoiceAccount];
                VendTable.FreightZone = vendor[UPSzone];
                VendTable.TaxGroup = vendor[SalestaxGroup];
VendTable.InclTaxSpecified = true;
                VendTable.InclTax = (AxdExtType_InclTax)Enum.Parse(typeof(AxdExtType_InclTax), vendor[PricesInclSalestax]);
                VendTable.TaxWithholdCalculateSpecified = true;
                VendTable.TaxWithholdCalculate = (AxdExtType_NoYesId)Enum.Parse(typeof(AxdExtType_NoYesId), vendor[CalculateWithholdingTax]);
                VendTable.InventLocation = vendor[Warehouse];
                VendTable.PurchAmountPurchaseOrderSpecified = true;
                VendTable.PurchAmountPurchaseOrder = (AxdExtType_PurchAmountPurchaseOrder)Enum.Parse(typeof(AxdExtType_PurchAmountPurchaseOrder), vendor[PurchaseOrderpricesAmount]);
                VendTable.PaymTermId = vendor[TermsofPayment];
                VendTable.PaymMode = vendor[Methodofpayment];                VendTable.DirPartyTable = new Vendors.VendServiceReference.AxdEntity_DirPartyTable_DirPartyTable[1];// AxdEntity_DirParty_DirPartyTable[1];
                VendTable.DirPartyTable[0] = org;
                //Add the specific customer to the list
                vendorList[0] = VendTable;
                AxdVendor.VendTable = vendorList;
                //Set the header fields
                AxdVendor.DocPurpose = Vendors.VendServiceReference.AxdEnum_XMLDocPurpose.Original;
                AxdVendor.DocPurposeSpecified = true;
                
                entityKey = vendSvcClient.create(null, AxdVendor);
            }
       }
    }
}