我創建了一個小型命令行應用程序,該應用程序從電子表格中讀取數據並將數據推入我們的Dynamics CRM聯機設置。實際導入與Dynamics SDK示例中的數據管理 - >數據導入(使用ImportWithCreate.cs)相同,但我已修改列映射以適應我們的需要。自動數據導入失敗,但沒有錯誤消息
當我運行命令行時,它報告它的成功(它解析,轉換並最終運行導入 - 按照示例)。檢查CRM我可以看到數據導入已經創建並運行,但它顯示爲失敗(令人煩惱的是,它沒有任何信息或失敗原因,我可以看到)。
它顯示在CRM這樣的...
那個圖形我可以推斷,導入文件已被用於尋找(我有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);
然後我更新導入文件創建以下(路徑只是抱着完整路徑我的CSV文件的變種導入)
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)
};
你可以分享代碼嗎? –