CRM 2011 Data Import - how to Create Column Mapping using XML file.
-
2012년 5월 15일 화요일 오후 7:35
Hi,
I have an xml like one below. I would like to create Column Mapping, Lookup and Pick list mappings based on the Data Type. For some reason this is not working, I am not sure if this is possible. Any help is greatly appreciated.
Sample XML:
<?xml version="1.0" encoding="utf-8" ?>
<Attributes>
<Attribute>
<Source>Account Name</Source>
<Destination DataType="string">name</Destination>
</Attribute>
<Attribute>
<Source>Account Number</Source>
<Destination DataType="string">accountnumber</Destination>
</Attribute>
<Attribute>
<Source>AddressType</Source>
<Destination DataType="picklist">address1_addresstypecode</Destination>
</Attribute>
<Attribute>
<Source>TechincalExpertise</Source>
<Destination DataType="lookup" TargetEntity="new_technicalexpertise" TargetEntityPrimaryKey="new_techincalexpertiseid" TargetSearchAttribute="new_name">new_technicalexpertise</Destination>
</Attribute>
</Attributes>
switch (DataType)
{
case "STRING":
createColumnmapping(importMapId, "TestAccounts", SourceAttribute, "account", TargetAttribute);
break;
case "LOOKUP":
// createLookupColumnMapping(importMapId, "TestAccounts", SourceAttribute, "account", TargetAttribute, LookupEntity, LookupPrimaryKey, LookupSearchAttribute);
break;
case "PICKLIST":
// createColumnmapping(importMapId, "TestAccounts", SourceAttribute, "account", TargetAttribute);
break;
}
static void createColumnmapping(Guid importMapId, string sourceEntityName, string sourceAttributename, string targetEntityName, string targetAttributeName)
{
ColumnMapping colMapping = new ColumnMapping()
{
// Set source properties.
SourceAttributeName = sourceAttributename,
SourceEntityName = sourceEntityName,
// Set target properties.
TargetAttributeName = targetAttributeName,
TargetEntityName = targetEntityName,
// Relate this column mapping with the data map.
ImportMapId =
new EntityReference(ImportMap.EntityLogicalName, importMapId),
ProcessCode = new OptionSetValue(1) // set to process
};
Guid colid = _service.Create(colMapping);
}
Thanks,
Karthik