web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Add User record in Entity Subgrid using c# in CRM 9.0

(0) ShareShare
ReportReport
Posted on by 2,667

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

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    No need to use associate, you can simple use update request, get records which you want to show in subgrid, update their lookup field (your parent entity) so that they can be shown in the subgrid.

    Let me know if you need more details.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 79 Super User 2026 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 58 Most Valuable Professional

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 42 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans