Display related records into the subgrid

0
114
Forum Post: Change the Filter On option on Opportunity Associated View for Account form


I have a question with JS.

One case record could have multiple sub case records.

I need to add a subgrid to the CASE entity and need to show all the tasks associated with the Sub-cases.

I have my JS attached for your review.

I appreciate your help.

In the case entity I want to add a subgrid to list all the tasks associated with the all sub cases.

function TasksFromSubCases (executionContext) {
    debugger;
    var formContext = executionContext.getFormContext();
    var childrenActivitiesSubgrid = formContext.getControl("Children_Activities");
    var inquiryId = formContext.data.entity.getId().replace('{', '').replace('}', '');
    
    var fetchXml = " <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
                                    "  <entity name='activitypointer'>"+
                                    "    <attribute name='activityid' />"+
                                    "    <filter type='and'>"+
                                    "      <condition attribute='activitytypecode' operator='eq' value='4212' />"+
                                    "    </filter>"+
                                    "    <link-entity name='incident' from='incidentid' to='regardingobjectid' link-type='inner' alias='ae'>"+
                                    "      <filter type='and'>"+
                                    "        <condition attribute='parentcaseid' operator='eq' value='" + inquiryId + "'/>"+
                                    "      </filter>"+
                                    "    </link-entity>"+
                                    "  </entity>"+
                                    "</fetch>";

     
    fetchXml = "?fetchXml=" + encodeURIComponent(fetchXml);
    Xrm.WebApi.retrieveMultipleRecords("activitypointer", fetchXml).then(
        function success(result) {  
                debugger;
                var activityValues = "";
                if (result.entities.length > 0) {
                result.entities.forEach(function (v) {
                    return (activityValues += '<value uitype="activitypointer">{' + v.activityid + "}</value>");
                });
                var activitiesFetchXmlFilter =
                '<filter type="and">\n'+
                '<condition attribute="activityid" operator="in">\n '+
                activityValues +
                +'</condition>\n '+
                +'</filter>';
                childrenActivitiesSubgrid.setFilterXml(activitiesFetchXmlFilter);
                childrenActivitiesSubgrid.refresh();
            } 
            else {
                var activitiesFetchXmlFilter = '<filter type="and">\n '+
                +'<condition attribute="activityid" operator="null" />\n '+
                +'</filter>';
                childrenActivitiesSubgrid.setFilterXml(activitiesFetchXmlFilter);
                childrenActivitiesSubgrid.refresh();
            }
            },
    function (error) {
        //console.log(error.message);
    }
    );



Source link

Leave a reply

Please enter your comment!
Please enter your name here