Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Passing Form Context to a Plugin using javascript for subgrid

(0) ShareShare
ReportReport
Posted on by 5
Hello, on the Account Form I have a subgrid that shows quotedetails (the custom direct relationship is already setup.  The requirement is to show the quotedetails of all the Accounts in the Account Hierarchy in the subgrid.  After various methods, I have gotten the closest with using a plugin that uses RetrieveMultiple to edit the FetchXML and return the filter I need.  It works with the hierarchy filter, however, only when hardcoded.  I have to set the subgrid to Show All Records, not show Only Related Records, because I need it to show quotedetails from other Accounts, i.e. Child Accounts.  Because it is Show All Records, the plugin doesn't have any context of what Account the User is on when the RetrieveMultiple gets the FetchXML.  So, I need some way for the Form to communicate to the plugin the Account ID of the form that the user is on.  If I can get that step done, then it should work!

Some methods I have tried that didn't work:
- doing all the filtering in javascript.  This works until the User interacts with the subgrid to filter by column, and then that filter overrides the javascript FetchXML.
- there is an Under condition in FetchXML that appears to work for hierarchies, but I got a message that it was unsupported when I tried that method in this scenario.

Here's an example of how I have tried to smuggle the GUID into the FetchXML using javascript, which hopefull I can get the Plugin to catch.  However, the plugin does not seem to see the GUID.  
 
Does anyone have any ideas for how to pass the GUID from clientside over to the Plugin, and what the best approach is here?
 
function passAccountGuidToPlugin() {
    var accountId = Xrm.Page.data.entity.getId();
    Xrm.Page.getControl(/HierarchyTest/).addPreSearch(function() {
        addCustomFilterToSubgrid(accountId);
    });
}
function addCustomFilterToSubgrid(accountId) {
    var fetchXml = /<filter><condition attribute='new_account' operator='eq' value='/ + accountId + /' /></filter>/;
    Xrm.Page.getControl(/HierarchyTest/).addCustomFilter(fetchXml);
}
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Passing Form Context to a Plugin using javascript for subgrid
    Hi Partner,
    Why not retrieve Multiple Records with WebApi and JavaScript directly? which avoids the difficulty of passing parameters to the plugin.
    One of the most important function of Xrm.WebApi is retrieveMultipleRecords, which allows developers to retrieve a collection of records from Dynamics 365 in a single API call.
    Syntax:
    Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback);

    I hope you can verify my answer if it helps you! If you have any questions, please feel free to contact me.
    Regards,
    Leah
  • Suggested answer
    powerx365 Profile Picture
    4 on at
    Passing Form Context to a Plugin using javascript for subgrid
    Don't think you can pass it to a Plugin, but what you could do is:
    • Create and register a custom Action that takes the inputs you need
    • Trigger that from JavaScript and pass the FormContext or the required parameters as input
    • Do the rest of the processing in C# in the Action
    • Pass the output/response
     
    Px - Logo.png

    Rajat Joshi

    Power x 365

    Experience the Difference

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans