Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to save subgrid value into form?

(1) ShareShare
ReportReport
Posted on by 12

Hello Team.

Need your help to get the resolution.

I have two entities opportunity and class. In the opportunity page i have added the subgrid of class. 

I want whenever i add the class in subgrid same class needs to save into classes field in the opportunity page. (I dont want to use java script on save event)

Below is the screenshot. 

2870.Issue.jpg

Can someone help me to get the other methods to achieve it?

*This post is locked for comments

  • Suggested answer
    TNS Profile Picture
    TNS 1,195 on at
    RE: How to save subgrid value into form?

    Hi,

    Like if you have added 0056 then 0056 class should be added in classes ,

    and then you have added 0057 then 0056 ; 0057 class should be added in classes field. If you want to achieve this you can use workflow :

    Use workflow on class entity on record creation.

    Create one more field name as old classes in opportunity entity.

    you have to update two times opportunity entity in workflow.

    ///condition you have to use in workflow

    so when any record is created on subgrid i.e. class entity then,

    first condition:

    classes field in opportunity entity value gets updated in old classes field if classes is not equal to null.

    then

    again update the opprtunity entity and set the value in classes field of (old classes field; Name field of class entity)

    Try this, might it can solve your issue .

  • Girish01 Profile Picture
    Girish01 12 on at
    RE: How to save subgrid value into form?

    Hello Pravin,

    I have developed the custom code. but it's again not updating the field value.

    could you please help me ? It's not giving any error

    Below code-

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    namespace SetClassId

    {

       public class SetClassIdToAssociatedOpp : IPlugin

       {

           public void Execute(IServiceProvider serviceProvider)

           {

               // Obtain the execution context from the service provider.

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

               // Get a reference to the Organization service.

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

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

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

               EntityReference target = null;

               EntityReference initialTargetEntity = null;

               EntityReferenceCollection relatedEntities;

               string relationshipName;

               EntityReference initialRelatedEntity;

                       if ((context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference) && (context.InputParameters.Contains("RelatedEntities") && context.InputParameters["RelatedEntities"] is EntityReferenceCollection))

               {

                   initialTargetEntity = (EntityReference)context.InputParameters["Target"];

                   relatedEntities = context.InputParameters["RelatedEntities"] as EntityReferenceCollection;

                   relationshipName = context.InputParameters["Relationship"].ToString();

                   initialRelatedEntity = relatedEntities[0];

                   //throw new Exception("" + initialTargetEntity.LogicalName + "::" + initialTargetEntity.Id);

               }                                                                                                                                                                                                                                                                      

               // if (context.Depth < 1)

               //     return;

               string fetch = @"<fetch distinct = 'true' mapping = 'logical'> " +

                             "<entity name='hnny_class'>" +

                             "<attribute name='hnny_classid'/>" +

                             "<attribute name='hnny_name'/>" +

                             "<attribute name='createdon'/>" +

                             "<order descending='false' attribute='hnny_name'/>" +

                             "<link-entity name='hnny_class_opportunity' intersect='true' visible='false' to='hnny_classid' from='hnny_classid'>" +

                             "<link-entity name='opportunity' to='opportunityid' from='opportunityid' alias='ab'>" +

                             "<filter type='and'>" +

                            "<condition attribute = 'opportunityid' operator= 'eq' value = '" + initialTargetEntity.Id + "' />" +

                             "</filter>" +

                             "</link-entity>" +

                             "</link-entity>" +

                             "</entity>" +

                             "</fetch>";

               FetchExpression exep = new FetchExpression(fetch);

               EntityCollection collection = service.RetrieveMultiple(exep);

               if (collection.TotalRecordCount > 1)

               {

                   string classNames = "";

                   foreach (Entity classes in collection.Entities)

                   {

                       if (classNames == "")

                           classNames = classes.Attributes.Contains("hnny_name") ? (String)classes["hnny_name"] : string.Empty;

                       else

                           classNames += classes.Attributes.Contains("hnny_name") ? (String)classes["hnny_name"] : string.Empty;

                   }

                   Entity opp = new Entity(initialTargetEntity.LogicalName, initialTargetEntity.Id);

                   opp["hnny_classes"] = classNames; // use classfiled logcal name

                   service.Update(opp);

               }

           }

       }

       }

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,231 on at
    RE: How to save subgrid value into form?

    Hi Girish,

    Please follow below steps:

    1. Get all records using either query expression or fetch expression inside plugin.

    2. Store and concat classes name in one string.

    3. Get opportunity lookup id in plugin

    4. Update opportunity field classes with concatenated field .

  • Girish01 Profile Picture
    Girish01 12 on at
    RE: How to save subgrid value into form?

    Hello Pravin,

    Thank you for your suggestion.

    Yes, classes field is the single line of text.

    As i am new into plugins. Could you please share some more information regarding this?

    Thank you for your help.

  • Girish01 Profile Picture
    Girish01 12 on at
    RE: How to save subgrid value into form?

    Hello Gautam,

    Thank you for your suggestion.

    I need to save all the values of classes subgrid into class field.

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,231 on at
    RE: How to save subgrid value into form?

    Hi Girish,

    I believe that classes field on opportunity form is nothing but single line text.

    You could achieve this by creating post-operation plugin on create of class entity.

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: How to save subgrid value into form?

    Hi Girish,

    If my understanding is correct when you are creating  new classes , the last created class name will be populate in the opportunity form field.

    If this is your requirement I would suggest to configure a workflow on create of class and update related  parent entity (opportunity) with the value of class name.

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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans