Hi,
I am trying to update columns from one CRM application to the other using ssis script component. The update was failing on an optionset field which is throwing this error:
"an item with the same key has already been added". Can somebody please look at the optionset and let me know how do I make changes.
public override void ContactInput_ProcessInputRow(ContactInputBuffer Row)
{
bool hasDulicate = false;
Entity existingLAPInterpreter = new Entity("new_lapinterpreter");
FilterExpression codeFilter = new FilterExpression();
codeFilter.AddCondition("new_interpretercontactid", ConditionOperator.Equal, Row.newAutoContactID);
QueryExpression query = new QueryExpression
{
EntityName = "new_lapinterpreter",
ColumnSet = new ColumnSet("new_firstnameintlap", "new_lastname", "new_interpreterlanguage", "new_emailintlap", "new_primaryphoneintlap", "new_interpretertype", "new_interpreterstate"),
Criteria = codeFilter
};
EntityCollection records = _orgService.RetrieveMultiple(query);
int totalrecords = records.Entities.Count;
foreach (Entity record in records.Entities)
{
if (record["new_firstnameintlap"] != null)
{
record["new_firstnameintlap"] = Row.FirstName;
}
if (record["new_lastname"] != null)
{
record["new_lastname"] = Row.LastName;
}
if (record["new_interpreterlanguage"] != null)
{
record["new_interpreterlanguage"] = Row.newprimarylanguage;
}
if (record["new_emailintlap"] != null)
{
record["new_emailintlap"] = Row.emailaddress1;
}
if (record["new_primaryphoneintlap"] != null)
{
record["new_primaryphoneintlap"] = Row.mobilephone;
}
if (record["new_interpreterstate"] != null)
{
record["new_interpreterstate"] = Row.address1stateorprovince;
}
OptionSetValue updateinterpreterType = new OptionSetValue();
if (record["new_interpretertype"]!=null)
{
switch (Row.newinterpretertype)
{
case 100000000:
updateinterpreterType.Value = 100000000;
break;
case 100000001:
updateinterpreterType.Value = 100000001;
break;
case 100000002:
updateinterpreterType.Value = 100000002;
break;
case 100000003:
updateinterpreterType.Value = 100000003;
break;
case 100000004:
updateinterpreterType.Value = 100000004;
break;
default:
updateinterpreterType.Value = 100000001;
break;
}
record.Attributes.Add("new_interpretertype", (OptionSetValue)updateinterpreterType);
}
_orgService.Update(existingLAPInterpreter);
hasDulicate = true;
}
}
Thanks for any help.
*This post is locked for comments
I have the same question (0)