web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

(0) ShareShare
ReportReport
Posted on by 1,532

Hi,

I have given up trying to use filtering subgrid using javascript. This just does not work after reading many request for answers.

So, I decided to go down the road using an "Action" to trigger a plugin that will create a new view or update an existing view to handle my filtering that is being used in a form subgrid.

I have read the below link. Seems like everyone is pointed to this link.  This works great. 

Modify CRM View Query or Filter Criteria on Demand Dynamically using Plugin Retrieve (by )

(https://community.dynamics.com/crm/b/misscrm360exploration/posts/modify-crm-view-query-or-filter-criteria-on-demand-dynamically-using-plugin-retrieve)

However,  I need to be able to update the subgrid view based on the users login.  The user could call the same view more than once in the form subgrid changing the filter.

This works with only 1 user if I update the existing view.  But how can I get this to work with more than 1 user user login to the same form subgrid.

For example my default subgrid view is "Case Form Inline Edit View".  If there are 2 users that login to the same form subgrid I want to be able to have user 1 have it's "Case Form Inline Edit View" and user 2 has it's "Case Form Inline Edit View".  Same view but with different filter criteria that would change in the form subgrid.

Is there a way to do this.

1) Is there a way to update the default view base on a user.

2) Can I change the default view dynamically

3) What are my options

pastedimage1564128911761v1.png

*This post is locked for comments

I have the same question (0)
  • RHOU Profile Picture
    65 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    I just created a very detailed feature wish to make this happen in a supported way for Unified Interface here:

    PLEASE VOTE!

    powerusers.microsoft.com/.../675538

  • Suggested answer
    Sanket87 Profile Picture
    160 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Hi ,

    I have added all the steps with screenshot in myb blog. Please refer and update if this works for you.[View:https://mylearningsfromcrm.blogspot.com/2019/07/filter-subgrid-using-javascript-it.html:750:50]

  • rthompson Profile Picture
    1,532 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Hi Sanket,

    When you have a chance would you please add screenshot on how you are attaching things together to make this work.

    Thanks

  • Suggested answer
    Sanket87 Profile Picture
    160 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Hi , 

    Please use the below javascript i have recently impemented for sub grid filtering using JS. You need to call this script on click of +new button of javascript from ribbon work bench

    https://mylearningsfromcrm.blogspot.com/2019/07/filter-subgrid-using-javascript-it.html

    // to filter promotion
    function FilterPartnerInPromotion() {
    debugger;
    try {
    var entityName = Xrm.Page.data.entity.getEntityName();
    if (entityName == "zh_promotion") {
    var viewId = "{72A70595-C721-4400-8D9B-1612E2A570DE}";//view id of lookup view
    var PromotionDistrubutionChannel = Xrm.Page.getAttribute("zh_promotionchannel").getValue();
    if (PromotionDistrubutionChannel != null) {
    var subgridLookup = Xrm.Page.getControl("lookup_Partner");
    subgridLookup.addPreSearch(function () {
    var fetchxml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    "<entity name='zh_partner'>" +
    "<attribute name='zh_name' />" +
    "<attribute name='zh_individualcianumber' />" +
    "<attribute name='zh_groupcia' />" +
    "<attribute name='zh_distributionchannel' />" +
    "<attribute name='zh_partnerid' />" +
    "<order attribute='zh_name' descending='false' />" +
    "<filter type='and'>" +
    "<condition attribute='zh_distributionchannel' operator='eq' value='" + PromotionDistrubutionChannel + "' />" +
    "</filter>" +
    "<link-entity name='zh_partner' from='zh_partnerid' to='zh_groupcia' visible='false' link-type='outer' alias='a_e3e60fcc0147e811a95a000d3a828e95'>" +
    "<attribute name='zh_individualcianumber' />" +
    "</link-entity>" +
    "</entity>" +
    "</fetch>";

    var layout = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
    "<row name='result' id='zh_partnerid'>" +
    "<cell name='zh_name' width='200' />" +
    "<cell name='zh_individualcianumber' width='200' />" +
    "<cell name='zh_distributionchannel' width='200' />" +
    "<cell name='zh_groupcia' width='200' />" +
    "</row>" +
    "</grid>";

    subgridLookup.addCustomView(viewId, "zh_partner", "Partner Lookup View", fetchxml, layout, true);
    });
    }
    }
    }
    catch (err) {
    WriteToErrorLog(err.message, "FilterPartnerInPromotion", "zh_UpdateQuoteFeilds");
    }
    }

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Is the retrieve only using the view that I have assigned in the form. - YES

    No, Retrieve Multiple plugins trigger only for the entity which you registered, you can not get form information inside plugin which means you can not pass parameter except user info and secure and insecure parameter in the plugin registration tool.

    Yes subgrid will return only related records and on top of that filter which you applied in the view.

  • rthompson Profile Picture
    1,532 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Last 2 question.

    When the subgrid is doing the "Retrieve Multiple" pre-operation. Is the retrieve only using the view that I have assigned in the form.

    Is there a away of retrieving the primary entity in the plugin without doing another retrieve on the primary.  I need to pass parameters to the subgrid that exist on the primary entity.

    Is the "Retrieve Multiple" only returning the subgrid records that are assigned to the primary entity

    If not how do I get the subgrid primary entity.  This way I am only filtering on the correct entities.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Yes you need to implement retrieve  multiple plugin.

    Make sure you should check user team or BU Or security roles as per your requirement before add the  filter condition inside plugin otherwise it will be impacted advanced find or any other subgrid as well.

    See here sample plugin -

    hachecrm2011.wordpress.com/.../

  • rthompson Profile Picture
    1,532 on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    Hi Goutam,

    Thanks for replying.

    I have never used the "Retieve Multiple" plugin (Pre-Operation).

    Based on you link.  How can I do a filter on the records ("CaseForm" entity) that will display in the subgrid view.

    Do I need to a "Retieve Multiple" plugin using the Post Operation as well?

    ConditionExpression caseId = new ConditionExpression()
    {
          AttributeName = "new_city",
          Operator = ConditionOperator.Equal,
          Values = entity.attribute["new_city"];
    };

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    This could be  work around ,  in the  retrieve multiple plugin code  instead of checking savedqueryid ,  you can check some predefined column name or filter condition to understand the plugin triggering  from sub-grid and modify query or add custom filter based on the condition. Make sure the filter condition should be unique in the view like lets say for contact entity firstname  = null .

    Here in my blog I did something like this  , hope this helps  -

    goutamdascrm.wordpress.com/.../

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Filtering Subgrid using JavaScript and FetchXML does not work. Filter subgrid using plugin savedquery

    This could be  work around ,  in the  retrieve multiple plugin code  instead of checking savedqueryid ,  you can check some predefined column name or filter condition to understand the plugin triggering  from sub-grid and modify query or add custom filter based on the condition. Make sure the filter condition should be unique in the view like lets say for contact entity firstname  = null .

    Here in my blog I did something like this  , hope this helps  -

    goutamdascrm.wordpress.com/.../

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans