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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

To get the selected records from sub-grid and pass it to Plugin

(0) ShareShare
ReportReport
Posted on by

Would like to know how the selected records from sub-grid can be passed to a plugin and process those records within plugin using C#. I have an entity form where a sub-grid of other entity is displayed, the user is allowed to select the some records from the sub-grid and clicking on submit button it should kick-off the plugin that would require the list of records selected from the sub-grid as input parameter.

It would be helpful if somebody could provide me guidance on this.

*This post is locked for comments

I have the same question (0)
  • Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    In your scenario, when the user clicks 'Submit', is that a custom button or did you mean save?

    Thanks,

     Aiden

  • Community Member Profile Picture
    on at

    Would like to enforce manual save here. If only any records are selected from the sub grid, user will be allowed to save the form and that should trigger the plugin. Is there any other way like lookup instead of subgrid to select the records of other entity and pass it to the plugin?

  • ashlega Profile Picture
    34,477 on at

    Hi,

     if it is an editable grid (is it?), you can get those ID-s using supported methods now. For example:

     www.inogic.com/.../events-in-dynamics-365-editable-grid

     So the idea would be:

    - In the "OnSave", get the id-s

    - Store them in a hidden field

    - Parse that field in the plugin

     For a regular grid, it might be possible as well(have a look at the last comment there):

      vikramxrm.blogspot.ca/.../read-subgrid-records-ms-crm-2013-using.html

  • Suggested answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Alex has the right idea on the strategy. For the regular grid though, you can't use all the code in that link because it's using non-supported methods (going against the DOM instead of supported JS methods).

    Since that post was written Microsoft has introduced methods to access the data in a supported way. Check out the details here: msdn.microsoft.com/.../dn932126

    Hope this helps! I'd appreciate if you'd mark our responses as Answering your question,

    Thanks,

     Aiden

    EDIT: The specific method you want to use is getSelectedRows()

  • Community Member Profile Picture
    on at

    Thanks for your response Aiden and Alex, have seen those examples but those are using JavaScript. I am looking something to get those selected rows in the Plugin (using C#). It would be great if you can show me how to pass the selected rows from the sub-grid to plugin (C#).

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi Madhan,

     There is no way to do it directly in the plugin.. selection only makes sense on the client side, so you have to pass it from the client to the server through that hidden field, and, then, parse it in the plugin.

    PS.Aiden, thanks for pointing out those supported methods.. things change over time:)

  • Verified answer
    Aiden Kaskela Profile Picture
    19,696 on at

    Hi,

    You'd need to do what Alex said to copy the values to a temp field. From a plugin, you don't have access to anything on the forms. All you have access to is fields on the record (what it was and what it will be).

    In order to get the values from the form to the plugin, you need to create a new text field on your entity called 'Selected Rows' or something, to temporarily store the values. Use the javascript examples to take the IDs and set them on the record as 'Selected Rows', then in your plugin you can use C# to read the IDs off that field.

    Thanks!

     Aiden

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    Instead of using JavaScript and Hidden field. I was able to get the values from the sub grid using C# from Plugin. Solution is to use N:N relationship for the sub grid (other entity) and a simple FetchXML to retrieve the items from the sub grid within Plugin using C#.

    Here is the link for the article with steps for implementing it.

    www.c-sharpcorner.com/.../to-get-multi-select-values-from-sub-grid-within-entity-form-from-plugin-using-c-sharp

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi Madhan,

     it depends on what you were trying to do - I think we were answering another question:) Yes, you can get ALL related records in the plugin. But you can actually SELECT some records in the subgrid, and that selection can be just a subset of the N:N (that's when you do need javascript):

    selection.PNG

  • Suggested answer
    Luke Sartain Profile Picture
    1,266 on at

    Another option could be to use Javascript and the getSelectedRows() function in an onSave event.  You could then pass an entitycollection to a custom action?

    getSelectedRows()

    https://msdn.microsoft.com/en-gb/library/dn932126.aspx

    EntityCollection/Custom Action

    community.dynamics.com/.../execute-action-with-entitycollection-parameter-using-web-api-in-dynamics-365

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans