如何在 Microsoft Dynamics AX 2009 中导入客户和供应商

本文介绍如何从 Microsoft Office Excel 电子表格导入 Microsoft Dynamics AX 2009 中的客户。 这些步骤介绍如何导入客户。 但是,也可以按照以下步骤导入供应商。

适用于: Microsoft Dynamics AX 2009
原始 KB 编号: 960729

若要在 Microsoft Dynamics AX 2009 中导入客户,请执行以下步骤:

  1. 在导航窗格中,依次选择“ 管理”、“ 定期”、“ 数据导出/导入”、“ Excel 电子表格”,然后选择“ 模板向导”。

  2. 在 Excel 模板向导中,选择“ 下一步”。

  3. “文件名” 字段中,输入要使用的文件的名称,然后选择“ 下一步”。

  4. 在向导的“选择表”页上,选择“可用对象”区域中的“CustTable”,选择>将对象插入到“所选对象”区域中的按钮,然后选择“下一步”。

    注意

    对于供应商,请在“可用对象”区域中选择“VendTable”。

  5. 在向导的 “生成字段”列表 页上,选择“ 下一步”。

  6. 在向导的 “选择字段” 页上,展开“ 客户”,然后选择要导入到 Microsoft Dynamics AX 的字段。 CustTable 导入的必填字段如下所示:

    • 客户帐户
    • 客户组
    • 货币
    • 语言
    • 通讯簿类型
    • 通讯簿 ID 名称
    • 地址
    • 付款条款
    • 国家/地区
    • 邮政编码
    • 状态
    • 搜索名称
    • 城市
    • Street name
    • 国家/地区
    • 状态
    • Company
  7. 选择“下一步”。

  8. 按照向导中的步骤完成导入。

  9. 在导航窗格中,依次选择“基本”、“设置”、“全局通讯簿”和“参数”。

  10. 选择“ 编号序列 ”选项卡,然后验证是否为通讯簿 ID 选择了编号序列。

    注意

    无法将所选编号序列设置为连续。

  11. 找到在步骤 3 中创建的文件。 将填充包含要导入的数据的 Excel 电子表格。

  12. “通讯簿 ID ”字段留空。 使用步骤 10 中设置的数字序列导入 Excel 电子表格时,将填充 “通讯簿 ID ”字段。

  13. 在导航窗格中,依次选择“ 管理”、“ 定期”、“ 数据导出/导入”,然后选择“ 定义组”。

  14. 在“ 数据导出/导入 ”对话框中,选择使用 Excel 模板向导创建的定义组,然后选择“ 表设置”。

  15. 在“ 表设置 ”对话框中,选择“ 转换 ”选项卡,然后将以下代码添加到窗口中默认行后面的 CustTable 表。

     str dirId;
     ;
    
    // Check that the custtable table is not associated to Party.
     if (!custTable.PartyId || custTable.PartyId == "")
     {
     // Create a Party entry for the customer.
     dirId = DirParty::createPartyFromCommon(custTable).PartyId;
     custTable.PartyId = dirId;
     }
     else
     {
     DirParty::updatePartyFromCommonInsert(custTable.PartyId,custTable);
     }
    

    若要导入供应商,请添加以下代码。

    str dirId;
     ;
    
    // Check that the vendtable table is not associated to Party.
     if (!vendTable.PartyId || vendTable.PartyId == "")
     {
     // Create a Party entry for the vendor.
     dirId = DirParty::createPartyFromCommon(vendTable).PartyId;
     vendTable.PartyId = dirId;
     }
     else
     {
     DirParty::updatePartyFromCommonInsert(vendTable.PartyId,vendTable);
     }
    
  16. 选择“运行转换检查”框,然后选择“编译”按钮。

    此步骤确定代码类型是否正确。

  17. 选择“ 预览 ”选项卡,验证字段是否与在 Excel 电子表格中输入的正确值匹配,然后关闭“ 表设置 ”对话框。

  18. 在“ 数据导出/导入 ”对话框中,选择创建的定义组,然后选择“ 导入”。

  19. “Excel 导入 ”对话框中,选择在步骤 3 中创建的 Excel 电子表格,然后选择“ 确定”。

  20. 验证客户是否已导入 CustTable 表,并在 DirPartyTable 表中创建了相应的记录。

导入客户后,可以为客户导入其他地址。 为此,请按照下列步骤操作:

  1. 在导航窗格中,依次选择“ 管理”、“ 定期”、“ 数据导出/导入”、“ Excel 电子表格”,然后选择“ 模板向导”。

  2. 在 Excel 模板向导中,选择“ 下一步”。

  3. “文件名” 字段中,输入要使用的文件的名称,然后选择“ 下一步”。

  4. 在向导的“选择表”页上,选择“显示所有表”选项,在“可用对象”区域中选择“地址”,选择>按钮将对象插入“所选对象”区域,然后选择“下一步”。

  5. 在向导的 “生成字段”列表 页上,选择“ 下一步”。

  6. 在向导的 “选择字段” 页上,展开 “Alt. address”,然后选择要导入到 Microsoft Dynamics AX 的字段。

    注意

    必须选择main表的Record-ID 和 Table ID

  7. 选择当前未使用的字符串的其他字段。 例如,选择“运营商帐号检查”框。

  8. 选择“下一步”。

  9. 按照向导中的步骤完成导入。

  10. 找到在步骤 3 中创建的 Excel 电子表格,然后填写要导入的数据。

    注意

    main 表的列表 ID 设置为 CustTable 的 77 或 505(对于 VendTable)。

  11. “引用 ”字段设置为 0

  12. 对于添加到电子表格的其他 运营商帐号 字段,请输入客户帐号。

  13. 在应用程序对象树 (AOT) 中,在 importData 以下 对象中找到 方法:

    Classes\SysDataImportDefBase

  14. importData在 方法中,按如下所示更改代码。

    现有代码

    _curcommon.doInsert();
    

    替换代码

    if (SysExpImpGroup::find(groupId).Type == SysExpImpType::Excel
     && _curCommon.TableId == tablenum(Address))
     {
     _curcommon.Insert();
     }
     else
     {
     _curcommon.doInsert();
     }
    
  15. 保存并编译 SysDataImportDefBase 类。

  16. 在导航窗格中,依次选择“ 管理”、“ 定期”、“ 数据导出/导入”,然后选择“ 定义组”。

  17. 在“ 数据导出/导入 ”对话框中,选择使用 Excel 模板向导创建的定义组,然后选择“ 表设置”。

  18. 在“ 表设置 ”对话框中,选择“ 转换 ”选项卡,然后将以下代码添加到窗口中默认行后面的 CustTable 表。

    str account;
     ;
    
    // If the address is for a customer and the recid for the customer is not specified
    if (address.AddrTableId == tablenum(CustTable) && address.AddrRecId == 0)
    {
     account = address.ShipCarrierAccount; // The additional field is added to the spreadsheet.
    
    // Fetch the recid of the customer.
     address.AddrRecId = CustTable::find(account).RecId;
     address.ShipCarrierAccount = '';
    }
    

    若要导入供应商,请添加以下代码。

    str account;
    ;
    
    // If the address is for a vendor and recid for the vendor is not specified
     if (address.AddrTableId == tablenum(VendTable) && address.AddrRecId == 0)
     {
     account = address.ShipCarrierAccount; // The additional field is added to the spreadsheet.
    
    // Fetch the recid of vendor.
     address.AddrRecId = VendTable::find(account).RecId;
     address.ShipCarrierAccount = '';
     }
    
  19. 选择“运行转换检查”框,然后选择“编译”按钮。

    此步骤确定代码类型是否正确。

  20. 选择“ 预览 ”选项卡,验证字段是否与在 Excel 电子表格中输入的正确值匹配,然后关闭“ 表设置 ”对话框。

  21. 在“ 数据导出/导入 ”对话框中,选择创建的定义组,然后选择“ 导入”。

  22. “Excel 导入 ”对话框中,选择在步骤 3 中创建的 Excel 电子表格,然后选择“ 确定”。

  23. 验证是否已为客户或供应商导入地址。