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,...
Suggested Answer

How to update a sub grid field based on field ?

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Ahmed Mehany Profile Picture
    40 on at

    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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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
    40 on at

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

  • Ahmed Mehany Profile Picture
    40 on at

    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);

                        }

                    }

               }

           }

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 185 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans