Hi All,
I have one entity named Interview & one subgrid with user available & am retrieving all interview records & trying to add particular user in that subgrid in Interview entity using console.Here subgrid is 1:n relationship means interview to user. I am using Associate Request message but its only updating last record only from collection.
Is it correct way to use Associate or do i need to use Update Message to associate user in subgrid if Update requires then what will be the syntax for this ?
QueryExpression EnInterview = new QueryExpression();
EnInterview.EntityName = "mdc_interviews";
EnInterview.ColumnSet = new ColumnSet(true);
EnInterview.Criteria = new FilterExpression();
EnInterview.Criteria.AddCondition("mdc_ismigrated", ConditionOperator.Equal, 755040000);
EntityCollection InterviewColls = Service.RetrieveMultiple(EnInterview);
AssociateRequest request1 = new AssociateRequest();
try
{
foreach (var enitem in InterviewColls.Entities)
{
QueryExpression userQuery = new QueryExpression("systemuser");
userQuery.Criteria.AddCondition("fullname", ConditionOperator.Equal, "Shahzad Khan");
EntityCollection col = Service.RetrieveMultiple(userQuery);
if (col.Entities.Count > 0)
{
request1.Target = new EntityReference(enitem.LogicalName, enitem.Id);
foreach (Entity Eninci in col.Entities)
{
request1.RelatedEntities = new EntityReferenceCollection();
request1.RelatedEntities.Add(new EntityReference("systemuser", Eninci.Id));
request1.Relationship = new Relationship("mdc_mdc_interviews_systemuser");
}
}
if (request1 != null)
Service.Execute(request1);
}
}
catch (Exception ex)
{
throw ex;
}
Any suggestions?
Thanks,
Jharana