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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans