Dynamics 365使用Import Entity更新记录时参考属性映射错误求助
Let's break down what's causing this error and how to fix it. The error message spells out the core problem clearly: you’ve added a LookupMapping (the "ReferenceMap" mentioned in the error) for an attribute that hasn’t been marked as a reference/lookup type in your ColumnMapping. Dynamics 365 requires explicit flags for lookup fields before you can define match rules for them.
Step 1: Mark the ColumnMapping as a Lookup Attribute
For reference fields like systemuserid, you need to add two critical attributes to your ColumnMapping entity to flag it as a lookup:
IsLookup: Set this totrueSourceAttributeType: Set this to the lookup option in your attribute type enum
Here’s how to modify your existing column mapping code:
Entity colMapping = new Entity(CrmColumnmapping.EntityLogicalName); colMapping.Attributes.Add(CrmColumnmapping.Fields.SourceAttributeName, dc.Caption); colMapping.Attributes.Add(CrmColumnmapping.Fields.SourceEntityName, "MySource"); colMapping.Attributes.Add(CrmColumnmapping.Fields.TargetAttributeName, dc.ColumnName); colMapping.Attributes.Add(CrmColumnmapping.Fields.TargetEntityName, dt.TableName); // Add these two lines to mark the field as a lookup colMapping.Attributes.Add(CrmColumnmapping.Fields.IsLookup, true); colMapping.Attributes.Add(CrmColumnmapping.Fields.SourceAttributeType, new OptionSetValue(CrmColumnmapping.OptionSets.SourceAttributeTypeValues.Lookup)); colMapping.Attributes.Add(CrmColumnmapping.Lookups.ImportMapId, new EntityReference(CrmImportmap.EntityLogicalName, importMap.Id)); colMapping.Attributes.Add(CrmColumnmapping.OptionSets.ProcessCode, new OptionSetValue(CrmColumnmapping.OptionSets.ProcessCodeValues.Option1_Process)); colMapping.Id = service.Create(colMapping);
Step 2: Verify Your LookupMapping Configuration
Your existing LookupMapping setup is on the right track for defining how to match source values to target lookup records:
- The first
LookupMappingusesOption2_Systemto specify the target entity’s matching attribute (e.g.,systemuseridordomainnamefor the System User entity) - The second uses
Option1_Sourceto define which source field holds the value to match on (e.g., a username or user ID from your input data)
Just double-check that the LookUpAttributeName values correspond to valid attributes on the target lookup entity (for the system mapping) and your source dataset (for the source mapping).
Step 3: Additional Checks for Update Imports
Since you’re running an update import, confirm these key details:
- Unique Matching Field: Ensure your import map includes a column mapping for a unique identifier (like the target entity’s primary key, e.g.,
accountid, or a custom unique field). Without this, Dynamics won’t know which existing record to update. - ImportMap Update Setting: When creating your
ImportMap, make sure you set itsUpdateattribute totrue(addimportMap.Attributes.Add(CrmImportmap.Fields.Update, true);before creating the entity if you haven’t already). This enables the import map to support update operations. - Import Mode: Your existing import code sets
ModeCodetoOption2_Update—that’s correct, keep this setting.
Example for systemuserid Mapping
If you’re specifically mapping to systemuserid, your LookupMapping values would look like this:
- For the system lookup mapping:
LookUpEntityName:"systemuser"LookUpAttributeName:"systemuserid"(or"domainname"if matching on the user’s email/domain)
- For the source lookup mapping:
LookUpAttributeName:"Source_UserId"(the name of the column in your source data that holds the user identifier)
By adding the IsLookup and SourceAttributeType flags to your column mapping, you’ll resolve the inconsistency error and let your lookup mapping rules work correctly for the update import.
内容的提问来源于stack exchange,提问作者Jérémie Huart

