locked
CRM 2011 (UR13): Custom grid view for related records activities RRS feed

  • Question

  • Hi,

    I have two entities A and B with a 1:N relationship from A to B. I have added a subgrid on entity A form to show the open activities. In this grid I would like to show the activities of entity A as well as activities of all related entity B records.

    Is this possible ?

    I've tried something like this but it didn't work. Please help.

    var fetchXml = "<fetch version='1.0' mapping='logical' distinct='false'>" +
                            "<entity name='activitypointer'>" +
                            "<attribute name='subject' />" +
                            "<attribute name='instancetypecode' /> " +
                            "<attribute name='scheduledend' />" +
                            "<attribute name='activitytypecode' />" +
                            "<attribute name='scheduledstart' />" +
                            "<attribute name='description' />" +
                            "<attribute name='activityid' />" +
                            "<order attribute='scheduledend' descending='false' />" +
                            "<filter type='and'>" +
                                "<condition attribute='isregularactivity' operator='eq' value='1' />" +
                                "<condition attribute='statecode' operator='in'>" +
                                    "<value>0</value>" +
                                    "<value>3</value>" +
                                "</condition>" +
                                "<filter type='or'>" +
                                    "<condition attribute='regardingobjectid' operator='eq' uitype='entity_A' value='" + Xrm.Page.data.entity.getId() + "' />" +
                                    "<condition attribute='regardingobjectid' operator='eq' uitype='entity_B' value='{9fb43627-5d0d-e211-a38d-005056b04707}' />" +
                                "</filter>" +
                            "</filter>" +
                            "</entity>" +
                            "</fetch>";
    var actGrid = document.getElementById("allopenactivities");
    actGrid.control.SetParameter("fetchXml", fetchXml);
    actGrid.control.refresh();


    Saturday, July 27, 2013 3:47 PM

Answers

  • Can you build the same query in advanced find to see if you get the same result?

    Maybe alert the fetchXml at the end of the function, or add a debugger into your code to ensure the related entity B record ID's are getting added to the query.

    Also, instead of using multiple conditions inside an 'or' filter, you can try using a single condition with multiple values using the 'In' operator (like you're doing with status).

    So instead of using:

    <filter type='or'>
      <condition attribute='regardingobjectid' operator='eq' uitype='entity_A' value='" + Xrm.Page.data.entity.getId() + "' />
      <condition attribute='regardingobjectid' operator='eq' uitype='entity_B' value='{9fb43627-5d0d-e211-a38d-005056b04707}' />
    </filter>

    You could use:

    <condition attribute='regardingobjectid' operator='in'>
      <value uitype='entity_A'>" + Xrm.Page.data.entity.getId() + "</value>
      <value uitype='entity_B'>{9fb43627-5d0d-e211-a38d-005056b04707}</value>
      <value uitype='entity_B'>{CF9A1C89-84F2-E211-833D-00155D04DC08}</value>
    </condition>

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    • Marked as answer by Rajesh Achanta Wednesday, July 31, 2013 12:27 PM
    Monday, July 29, 2013 8:52 AM

All replies

  • Hi,

    It's not possible in a single query, since we cannot use 'Or' conditions across link entities. However since you're using JavaScript you can retrieve the ID's of all related entity B records first, and then add each ID into the 'Or' condition of your view XML using a for loop.

    You would need to use a SOAP request to retrieve the ID's.

    Once you have your ID's, you can add each into the fetch like this:

    fetchXml += "<filter type='or'>" +
        "<condition attribute='regardingobjectid' operator='eq' uitype='entity_A' value='" + Xrm.Page.data.entity.getId() + "' />";
    
    for (var i = 0; i < results.length; i++) {
        fetchXml += "<condition attribute='regardingobjectid' operator='eq' uitype='entity_B' value='" + results[i] + "' />";
    }
    
    fetchXml += "</filter>";

    Where 'results' is an array of your entity B ID's.

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Sunday, July 28, 2013 3:46 AM
  • Hi Paul,

    thanks for the reply. Sorry I didn't describe the issue properly.

    I did use a for loop to get all the related records and then passed on the filter condition. So my 'or' filter has multiple conditions as you mentioned.

    The problem is that the Activity Grid refreshes but does not display the entity B records. It still displays only entity A records.

    Monday, July 29, 2013 6:26 AM
  • Can you build the same query in advanced find to see if you get the same result?

    Maybe alert the fetchXml at the end of the function, or add a debugger into your code to ensure the related entity B record ID's are getting added to the query.

    Also, instead of using multiple conditions inside an 'or' filter, you can try using a single condition with multiple values using the 'In' operator (like you're doing with status).

    So instead of using:

    <filter type='or'>
      <condition attribute='regardingobjectid' operator='eq' uitype='entity_A' value='" + Xrm.Page.data.entity.getId() + "' />
      <condition attribute='regardingobjectid' operator='eq' uitype='entity_B' value='{9fb43627-5d0d-e211-a38d-005056b04707}' />
    </filter>

    You could use:

    <condition attribute='regardingobjectid' operator='in'>
      <value uitype='entity_A'>" + Xrm.Page.data.entity.getId() + "</value>
      <value uitype='entity_B'>{9fb43627-5d0d-e211-a38d-005056b04707}</value>
      <value uitype='entity_B'>{CF9A1C89-84F2-E211-833D-00155D04DC08}</value>
    </condition>

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    • Marked as answer by Rajesh Achanta Wednesday, July 31, 2013 12:27 PM
    Monday, July 29, 2013 8:52 AM
  • Paul,

    Thanks for the reply again. The 'in' operator condition worked. However, it looks like we have to set the subgrid properties to display 'All Records' instead of 'Related Records', otherwise the grid won't refresh.

    Wednesday, July 31, 2013 12:28 PM