Aşağıdaki kod ile lead ve account arasındaki mapping edilen kolonları çekebiliriz.
EntityCollection attributeMaps =
GetAttributesMap(crmService, "lead", "account");
Entity account =
new Entity("account");
foreach (var item
in attributeMaps.Entities)
{
string
sourceAttributeName =
item.GetAttributeValue<string>("sourceattributename");
string
targetAttributeName =
item.GetAttributeValue<string>("targetattributename");
if
(lead.Attributes.Contains(sourceAttributeName))
{
if
(sourceAttributeName.ToLower() == "leadid")
account[targetAttributeName] = new EntityReference("lead",
lead.Id);
else
account[targetAttributeName] = lead[sourceAttributeName];
}
}
//account["name"] = companyname;
accountid =
crmService.Create(account);
private EntityCollection
GetAttributesMap(IOrganizationService serv, string sourceentityname, string
targetentityname)
{
QueryExpression query = new
QueryExpression()
{
EntityName =
"attributemap",
ColumnSet = new
ColumnSet("sourceattributename", "targetattributename"),
LinkEntities =
{
new LinkEntity
{
LinkFromEntityName="attributemap",
LinkFromAttributeName="entitymapid",
LinkToEntityName
= "entitymap",
LinkToAttributeName = "entitymapid",
LinkCriteria =
new FilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new
ConditionExpression("sourceentityname",ConditionOperator.Equal,sourceentityname),
new
ConditionExpression("targetentityname",ConditionOperator.Equal,targetentityname)
}
}
}
},
Criteria = new FilterExpression
{
FilterOperator =
LogicalOperator.And,
Conditions =
{
new
ConditionExpression("parentattributemapid",ConditionOperator.Null),
new
ConditionExpression("sourceattributename",
ConditionOperator.NotNull),
new
ConditionExpression("targetattributename", ConditionOperator.NotNull)
}
}
};
return
serv.RetrieveMultiple(query);
}
Hiç yorum yok:
Yorum Gönder