Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Edit Subgrid using a plugin with a custom FetchXML

Posted on by Microsoft Employee

I have a requirement to roll up activities from a child and grandchild custom entity to the custom parent entity. The option for Cascade all rollup is disabled for custom entities for whatever reason so I created a custom FetchXML to apply to the subgrid. The XML works fine but when I look at the subgrid it says "No activity records found" however when I click on the "See the records associated with this view" button it shows the records I need.

My step is registered on RetrieveMultipl Activitypointer - Pre operation Sync

Is there anyway to display the records on the subgrid so the user dosnt have to click on the "Records associated" button?

emptysubgrid.PNG

recordsassociated.PNG

3073.step.PNG

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Edit Subgrid using a plugin with a custom FetchXML

    I also checked the views and the plugin is overriding all the fetchxml for any view I choose after I click the button. No matter which view I go to the results are the same. I just cant get them to display!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Edit Subgrid using a plugin with a custom FetchXML

    Javascript code (took out the XML because its the exact same as plugin)

     var gridActivities =window.parent.document.getElementById("Grid_SalesTripActivities");

        var tripId= Xrm.Page.data.entity.getId();

        if (gridActivities == null) {

            setTimeout(function () { filterActivities(); }, 2000);

            return;

        }

       //fetch xml code

       var fetchXml = (Same FetchXML from code above)

       if (gridActivities.control != null) {

              console.log(gridActivities);

           gridActivities.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid  

           gridActivities.control.refresh(); //refresh the sub grid using the new fetch xml

              console.log(gridActivities);

       }

       else {

           setTimeout(filterActivities, 500);

       }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Edit Subgrid using a plugin with a custom FetchXML

    Ive been trying to figure out how to assign the FetchXml to the default view of the subgrid but havent had any luck yet. I cant assign the "See the Records associated with this view" view to the subgrid because its an associated view and not a system view.

    I also tried using Javascript but I'm unable to get it to return any records at all with that. Using JS as an Onload method and using timeouts and refresh command.

    Plugin Code

    QueryExpression query = (QueryExpression)context.InputParameters["Query"];

                       Guid tripId = new Guid();

                       foreach (LinkEntity lnk in query.LinkEntities)

                       {

                           foreach (ConditionExpression con in lnk.LinkCriteria.Conditions)

                           {

                               foreach (Guid val in con.Values)

                               {

                                   tripId = val;                            

                               }              

                           }                  

                       }                    

                       FetchXmlToQueryExpressionRequest req = new FetchXmlToQueryExpressionRequest();

                       req.FetchXml = "<fetch top='50' >" +

                                     "<entity name='activitypointer' >" +

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

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

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

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

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

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

                                       "<filter type='or' >" +

                                         "<condition entityname='customervisit' attribute='originatingtrip' operator='eq' value='"+tripId+"' />" +

                                         "<filter type='or' >" +

                                           "<condition entityname='accountaffected' attribute='originatingtrip' operator='eq' value='"+tripId+"' />" +

                                         "</filter>" +

                                       "</filter>" +

                                       "<link-entity name='accountaffected' from='accountaffectedid' to='regardingobjectid' link-type='outer' />" +

                                       "<link-entity name='customervisit' from='customervisitid' to='regardingobjectid' link-type='outer' />" +

                                     "</entity>" +

                                   "</fetch>";

                       FetchXmlToQueryExpressionResponse resp = (FetchXmlToQueryExpressionResponse)service.Execute(req);

                       context.InputParameters["Query"] = resp.Query;

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Edit Subgrid using a plugin with a custom FetchXML

    It looks like different views are being displayed in the initial subgrid compared to when you click on the "See the records associated with this view", and that may affect your plugin logic. I think you'll need to trace what information is passed to the plugin in each case

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans