Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

How to update a sub grid field based on field ?

Posted on by 40

 I 5430.download.pnghave est.close date in opportunity and sub grid of product  i want to assign the value of est.close date to valid_ to in product sub grid when you choose the opportunity and save these assign the value of close date to the valid to field in product sub grid  and when you open  the opportunity again you can not choose the product that used in another product 

when it used in other opportunity

  • Ahmed Mehany Profile Picture
    Ahmed Mehany 40 on at
    RE: How to update a sub grid field based on field ?

    i have done these plugin and it's not working

     public void Execute(IServiceProvider serviceProvider)

           {

               // extract the service provider

               ITracingService tracingservice = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

               IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               IOrganizationServiceFactory srevicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = srevicefactory.CreateOrganizationService(context.UserId);

               if(context.InputParameters.Contains("Target")&&context.InputParameters["Target"] is Entity)

               {

                   Entity entity = (Entity)context.InputParameters["Target"];

                   if (entity.Contains("name"))

                    {

                        var fetch = @"<fetch no-lock='true' >

                                <entity name='opportunity' >

                                  <attribute name='contactid'/>

                                  <filter>

                                    <condition attribute='opportunityid' operator='eq' value='{0}' />

                                  </filter>

                                </entity>

                              </fetch>";

                        var fetchXML = string.Format(fetch, entity.Id);

                        var allContacts = service.RetrieveMultiple(new FetchExpression(fetchXML)).Entities;

                        foreach (var contactEnt in allContacts)

                        {

                            Entity contactToUpdate = new Entity("opportunityproduct", contactEnt.Id);

                            contactToUpdate["new_valid_to"] = entity["estimatedclosedate"];

                            service.Update(contactToUpdate);

                        }

                    }

               }

           }

  • Ahmed Mehany Profile Picture
    Ahmed Mehany 40 on at
    RE: How to update a sub grid field based on field ?

    can you guide me in example of how to use plugin to update subgrid record

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: How to update a sub grid field based on field ?

    Hello,

    If you want to use this approach I would recommend to use Plugin or Flow to loop through the child records and update the field on the change of the field on the parent record.

  • Ahmed Mehany Profile Picture
    Ahmed Mehany 40 on at
    How to update a sub grid field based on field ?

    screenshot_2D00_10_2D00_4_2D00_2_2D00_228_2D00_INMA_2D00_main_2D00_aspx_2D00_1608121620675.png

    i have est.close date in opportunity and sub grid of product  i want to assign the value of est.close date to valid_ to in product sub grid when you choose the opportunity and save these assign the value of close date to the valid to field in product sub grid  and when you open  the opportunity again you can not choose the product that used in another product 

    when it used in other opportunity

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans