Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Passing Form Context t...
Sales forum
Unanswered

Passing Form Context to a Plugin using javascript for subgrid

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
    Leah Ju 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
    powerx365 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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,353 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans