自动数据导入失败但没有错误消息

时间:2014-01-08 11:48:49

标签: dynamics-crm-2011 dynamics-crm microsoft-dynamics

我创建了一个小型命令行应用程序,可以从电子表格中读取并将数据推送到我们的Dynamics CRM在线设置中。实际导入与数据管理相同 - >在Dynamics SDK示例中导入数据(使用ImportWithCreate.cs),但我修改了列映射以满足我们的需要。

当我运行命令行时,它报告它成功(它解析,转换并最终运行导入 - 根据示例)。检查CRM我可以看到数据导入已经创建并运行但是显示为失败(令人烦恼的是它没有消息或我可以看到失败的原因)。

它像CRM一样在CRM中显示......

failed import

查看该图形,我可以推断出已经使用了导入文件(我有一个包含10行的测试文件,导入总共报告了10条记录)。令人困惑的是,它说没有记录成功,部分成功或失败?!

如果我尝试手动使用相同的地图导入相同的测试数据文件,那么它可以正常工作。

有没有人指出我如何调试它并找出为什么这不能通过代码工作?

根据要求,这里有一些代码片段。导入本质上是Dynamics SDK中的数据管理示例,具有以下修改。

我用以下

替换了样本映射的示例
// Mapping - Quote Name (text).
ColumnMapping colMappingQuoteName = new ColumnMapping()
{
    SourceAttributeName = "Name",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "name",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdQuoteName = _serviceProxy.Create(colMappingQuoteName);

// Mapping - Potential Customer (lookup).
ColumnMapping colMappingPotentialCustomer = new ColumnMapping()
{
    SourceAttributeName = "PotentialCustomer",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "customerid",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdPotentialCustomer = _serviceProxy.Create(colMappingPotentialCustomer);

LookUpMapping parentLookupMappingPotentialCustomer = new LookUpMapping()
{
    ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingIdPotentialCustomer),
    ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process),
    LookUpEntityName = Account.EntityLogicalName,
    LookUpAttributeName = "name",
    LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.System)
};
Guid parentLookupMappingId = _serviceProxy.Create(parentLookupMappingPotentialCustomer);

// Mapping - PriceList (lookup).
ColumnMapping colMappingPriceList = new ColumnMapping()
{
    SourceAttributeName = "PriceList",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "pricelevelid",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdPriceList = _serviceProxy.Create(colMappingPriceList);

LookUpMapping parentLookupMappingPriceList = new LookUpMapping()
{
    ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingIdPriceList),
    ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process),
    LookUpEntityName = PriceLevel.EntityLogicalName,
    LookUpAttributeName = "name",
    LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.System)
};
Guid parentLookupMappingIdPriceList = _serviceProxy.Create(parentLookupMappingPriceList);

// Mapping - Currency (lookup).
ColumnMapping colMappingCurrency = new ColumnMapping()
{
    SourceAttributeName = "Currency",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "transactioncurrencyid",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdCurrency = _serviceProxy.Create(colMappingCurrency);

LookUpMapping parentLookupMappingCurrency = new LookUpMapping()
{
    ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingIdCurrency),
    ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process),
    LookUpEntityName = TransactionCurrency.EntityLogicalName,
    LookUpAttributeName = "currencyname",
    LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.System)
};
Guid parentLookupMappingIdCurrency = _serviceProxy.Create(parentLookupMappingCurrency);

// Mapping - Effective From (text).
ColumnMapping colMappingEffectiveFrom = new ColumnMapping()
{
    SourceAttributeName = "EffectiveFrom",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "effectivefrom",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdEffectiveFrom = _serviceProxy.Create(colMappingEffectiveFrom);

// Mapping - Effective To (text).
ColumnMapping colMappingEffectiveTo = new ColumnMapping()
{
    SourceAttributeName = "EffectiveTo",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "effectiveto",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdEffectiveTo = _serviceProxy.Create(colMappingEffectiveTo);

// Mapping - Owner (lookup).
ColumnMapping colMappingOwner = new ColumnMapping()
{
    SourceAttributeName = "Owner",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "ownerid",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdOwner = _serviceProxy.Create(colMappingOwner);

LookUpMapping parentLookupMappingOwner = new LookUpMapping()
{
    ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingIdOwner),
    ProcessCode = new OptionSetValue((int)LookUpMappingProcessCode.Process),
    LookUpEntityName = SystemUser.EntityLogicalName,
    LookUpAttributeName = "fullname",
    LookUpSourceCode = new OptionSetValue((int)LookUpMappingLookUpSourceCode.System)
};
Guid parentLookupMappingIdOwner = _serviceProxy.Create(parentLookupMappingOwner);

// Mapping - Status (picklist).
ColumnMapping colMappingStatus = new ColumnMapping()
{
    SourceAttributeName = "Status",
    SourceEntityName = "PTBQuote",
    TargetAttributeName = "statecode",
    TargetEntityName = Quote.EntityLogicalName,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    ProcessCode = new OptionSetValue((int)ColumnMappingProcessCode.Process)
};
Guid colMappingIdStatus = _serviceProxy.Create(colMappingStatus);

// Picklist values - any changes will need to be confirmed against Dynamics CRM (TargetValue being the tricky bit to get right)
PickListMapping pickListMappingStatus0 = new PickListMapping()
{
    SourceValue = "Draft",
    TargetValue = 0,
    ColumnMappingId = new EntityReference(ColumnMapping.EntityLogicalName, colMappingIdStatus),
    ProcessCode = new OptionSetValue((int)PickListMappingProcessCode.Process)
};
Guid picklistMappingIdStatus0 = _serviceProxy.Create(pickListMappingStatus0);

然后我将导入文件创建更新为以下内容( path 只是一个包含我正在导入的csv文件的完整路径的var)

importFile = new ImportFile()
{
    Content = BulkImportHelper.ReadCsvFile(path),
    Name = "Automated quote import",
    IsFirstRowHeader = true,
    ImportMapId = new EntityReference(ImportMap.EntityLogicalName, importMapId),
    UseSystemMap = false,
    Source = path,
    SourceEntityName = "PTBQuote",
    TargetEntityName = Quote.EntityLogicalName,
    ImportId = new EntityReference(Import.EntityLogicalName, importId),
    EnableDuplicateDetection = false,
    FieldDelimiterCode =
        new OptionSetValue((int)ImportFileFieldDelimiterCode.Comma),
    DataDelimiterCode =
        new OptionSetValue((int)ImportFileDataDelimiterCode.DoubleQuote),
    ProcessCode =
        new OptionSetValue((int)ImportFileProcessCode.Process)
};

1 个答案:

答案 0 :(得分:0)

导航至设置>系统工作。这样,您可以检查各个导入作业的状态和任何错误消息:Parse,Transform,Import。您可能必须过滤网格或对系统作业类型执行高级查找才能找到所需的记录。