locked
delete a row from the subgrid without deleting the record from CRM itself RRS feed

  • Question

  • I have a subgrid of the users in the custom entity.

    How can I have the user delete a row from the subgrid without deleting the user record itself from CRM?


    Thanks! Sneha

    Wednesday, February 15, 2012 6:53 AM

Answers

  • Hello,

    You can use N:N relationship between entities, if it's suits you, then you can delete the user record from subgrid. As far as I know for 1:N relationship it's impossible using out of box customization, maybe there is the way to solve this issue using code.

    Wednesday, February 15, 2012 7:07 AM
    Answerer
  • Try to use Remove button instead of Delete button.

    Wednesday, February 15, 2012 10:52 AM
    Answerer
  • I've created custom entity, made N:N relationship Test (my custom entity): User. And there is Remove button. You can see ToolTip. This will solve your issue.

    Wednesday, February 15, 2012 12:37 PM
    Answerer
  • Hi Sneha,

    In you case it will be displaying all the records of "ReturnReason" entity in the subgrid and you will be only getting option to delete or create a record.

    for achieving this create a N:N relationship 

    chenge you properties of subgrid as per the below image..

    I am adding this Subgrid in Account Form .

    "Contact Realtions" is N:N relationship with the Account to Contact Entity 


    With Regards Athul MT If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)



    Thursday, February 16, 2012 5:31 AM
  • Hi Sneha,

    The purpose of the ‘Remove’ button is to remove a relationship between two records (disassociate).
    As such, you will only get the ‘Remove’ button where a relationship between the current record and the records within the subgrid exists.

    If the subgrid which you are showing just contains a list of all/subset of “active” records (… if I understood correctly?) which may not be related to the currently open record – then it is understandable that you will not see the ‘Remove’ button … in this case, a relationship may not exist so how can you be allowed to remove it?

    Not sure I fully understand the purpose which the subgrid is trying to fulfill but hope that helps …

    Thanks,
    Maryse


    The xRM Architect:

    Friday, February 17, 2012 1:02 AM
  • Hi Maryse,

    Thank you so much for reply,

    What I want is, I want to condition the record shown in subgrid, it should only list the record which are related to the value seleted in  lookup , so for that 

    I created a subgrid and bind it via fetchxml using(http://crmgreenbible.blogspot.in/2011/07/crm-2011-change-subgrid-fetchxml.html) so I was able to see the records which where related to the Id selected in Lookup ,but problem here was of deletion when I deleted record here it was deleting it from CRM .

    so there was another sol'n suggested that was creating N:N relation so that it will have remove button but here I am not able to bind this grid with the Fecthxml(to satisfy  the condition) so that too failed for me

    One more sol'n is to bind the Add Existing button of the subgird(using http://www.mscrmking.com/2011/06/crm-2011-how-to-filter-add-existing)

    but that too didn’t work for me...

    Please it will be real help if u can give me some sol'n so that I can show user the records related to the selected values from lookup...

    any sort of suggestions are  welcomed...

    Thanks

    Sneha



    Thanks! Sneha

    Friday, February 17, 2012 9:05 AM
  • Hi Sneha,

    I think the issue here is that there is no “direct” relationship between the Account and the records you are wanting to show within the sub-grid.
    I believe that the buttons on the ribbon will apply to sub-grids only where there is a “direct” relationship between the records.

    For example, on the Account form, you have a “Primary Contact” lookup (relationship to a Contact), and are showing a sub-grid of “Books” (custom entity, related to the selected Contact).
    The link between the Account form and the “Book” sub-grid is simply that you are showing “All Records” (ie. there is actually no relationship between the Account and Books) – all you are doing is filtering this list of “Books” to only show those related to the selected “Contact”, this still does not change the relationship between the sub-grid and the parent form.

    As such, because there is no relationship, the options you will have on the ribbon when the sub-grid is selected will be the same as those available when looking at any Book view (for example) outside the scope of a related record – there is no recognition of a relationship because it doesn’t exist.

    I think to achieve what you are asking for, you need to do the following:

    • Create a relationship (many to many) between Accounts and Books – and do not show this in the left navigation menus.  
    • When a Contact is associated to a Book, also associate the Book to the Account (related to the Contact) … and visa versa, plugin will be best for this.
    • *When a Contact is disassociated from a Book, also disassociate the Book from the Account (related to the Contact) IF there are no other child Contacts also linked to this Book… and visa versa, plugin will be best for this.


    This is assuming:

    • Each Account is related to many Contacts; Each Contact is related to one Account
    • Each Contact is related to many Books; Each Book can be related to many Contacts
    • Each Book can be related to many Accounts; Each Account can be related to many Books

    (Not sure if the above in what you have/are after … just taking a guess!)

    This should now allow you to add a sub-grid on the Account form selecting “Only Related Records” and then the new relationship to Books – as this will be a direct relationship, you should now be able to see the “Remove” button.

    In order to keep all the relationships in-sync, you will also need to do the following:

    • When a Book is dissociated from an Account (using the “remove” button for the sub-grid), disassociated the Book from the selected “Primary Contact” (on the Account) … this should in turn trigger a check on (*) to  verify if the relationship between the Book and the Account also needs to be removed.

    I haven’t actually tested this (sorry I’m not very technical) but this should be one way of giving you the desired effect …

    Also, this is quite a bit of work so I would re-confirm the requirement for this to ensure it is essential ... otherwise, it may just be easier to tell users to open the related “Contact” and view/add/remove the Books (for example) directly from there … !!

    Good luck!

    Thanks,
    Maryse


    The xRM Architect:

    Tuesday, February 21, 2012 12:06 AM
  • Hi Sneha,

    No worries, glad I was able to help :)

    I haven’t written any plugins before but these seem to be the right events to use …

    AssociateRequest Class
    http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.associaterequest.aspx

    DisassociateRequest Class
    http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.disassociaterequest.aspx

    You can also get more details in the CRM 2011 SDK:
    http://www.microsoft.com/download/en/details.aspx?id=24004&lc=1033

    Good luck!

    Thanks,
    Maryse

    The xRM Architect:

    Tuesday, February 21, 2012 10:45 PM

All replies

  • CRM does not have such capabilities;

    For you case, I would suggest you use the deactivate record feature. COnfigure your sub grid view to only display active records.

    Let the user deactivate the records instead, but still can view it in another view, for example view to show all records.(with deactivated record)

    thanks


    regards,
    Toong Yang
    http://eastoceantechnical.blogspot.com/

    Wednesday, February 15, 2012 6:59 AM
  • Hello,

    You can use N:N relationship between entities, if it's suits you, then you can delete the user record from subgrid. As far as I know for 1:N relationship it's impossible using out of box customization, maybe there is the way to solve this issue using code.

    Wednesday, February 15, 2012 7:07 AM
    Answerer
  • hi Toong,

    Thanks for ur suggestion ,I tried to do it ur way but I am not able to find Fetchxml which I m binding to subgris which will show only active record,if u have any idea,plz let me know...


    Thanks! Sneha

    Wednesday, February 15, 2012 9:43 AM
  • Hi Maryna,

    I tried making it N:N ,but when I deleted the record from subgrid it delete it from CRM also....

    :(


    Thanks! Sneha

    Wednesday, February 15, 2012 9:47 AM
  • Try to use Remove button instead of Delete button.

    Wednesday, February 15, 2012 10:52 AM
    Answerer
  • hi Maryna ,

    I tried that too,actually there is no remove button in ribbion so I added a custom button and on click of it I get the Ids of selected record but not able to remove it from subgrid

    the Selected Record Ids of a Sub Grid in CRM 2011 using javascript
    Code Snippet:
        var gridControl = document.getElementById("yourSubGridName").control;
        var ids = gridControl.get_selectedIds();

    do u have any Idea how to remove the selected ids from subgrid?

    thanks !

    Sneha


    Thanks! Sneha

    Wednesday, February 15, 2012 11:08 AM
  • I've created custom entity, made N:N relationship Test (my custom entity): User. And there is Remove button. You can see ToolTip. This will solve your issue.

    Wednesday, February 15, 2012 12:37 PM
    Answerer

  • I have created N:N relation while createing Subgrid I have not used that relation as I am binding it with Fetchxml instead I have used the Entity itself,I am not able to see Remove Button...Kindly help...

    Thanks! Sneha


    • Edited by SnehaDeore Wednesday, February 15, 2012 1:00 PM
    Wednesday, February 15, 2012 12:58 PM
  • Could you please provide screenshot of subgrid you've used properties?
    Wednesday, February 15, 2012 2:47 PM
    Answerer
  • hi,

    below is the Image which shows the subgrid for Return Reason and its has N:N relation with Terms 


    and via javascript I m binding it 

     //Inject the new fetchXml
      reaturnreason.control.setParameter("fetchXml", fetchXml2);
      //Force the subgrid to refresh
     reaturnreason.control.refresh();

    Thanks! Sneha


    • Edited by SnehaDeore Thursday, February 16, 2012 4:42 AM
    Thursday, February 16, 2012 4:40 AM
  • Hi Sneha,

    In you case it will be displaying all the records of "ReturnReason" entity in the subgrid and you will be only getting option to delete or create a record.

    for achieving this create a N:N relationship 

    chenge you properties of subgrid as per the below image..

    I am adding this Subgrid in Account Form .

    "Contact Realtions" is N:N relationship with the Account to Contact Entity 


    With Regards Athul MT If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)



    Thursday, February 16, 2012 5:31 AM
  • Hi,

    if I make it 'related record ' then its not allowing me to bind the fetchXml to sub grid....

    plz if u have some other sol'n,plz let me know

    thanks

    Sneha


    Thanks! Sneha

    Thursday, February 16, 2012 6:04 AM
  • Hi Sneha,

    The purpose of the ‘Remove’ button is to remove a relationship between two records (disassociate).
    As such, you will only get the ‘Remove’ button where a relationship between the current record and the records within the subgrid exists.

    If the subgrid which you are showing just contains a list of all/subset of “active” records (… if I understood correctly?) which may not be related to the currently open record – then it is understandable that you will not see the ‘Remove’ button … in this case, a relationship may not exist so how can you be allowed to remove it?

    Not sure I fully understand the purpose which the subgrid is trying to fulfill but hope that helps …

    Thanks,
    Maryse


    The xRM Architect:

    Friday, February 17, 2012 1:02 AM
  • Hi Maryse,

    Thank you so much for reply,

    What I want is, I want to condition the record shown in subgrid, it should only list the record which are related to the value seleted in  lookup , so for that 

    I created a subgrid and bind it via fetchxml using(http://crmgreenbible.blogspot.in/2011/07/crm-2011-change-subgrid-fetchxml.html) so I was able to see the records which where related to the Id selected in Lookup ,but problem here was of deletion when I deleted record here it was deleting it from CRM .

    so there was another sol'n suggested that was creating N:N relation so that it will have remove button but here I am not able to bind this grid with the Fecthxml(to satisfy  the condition) so that too failed for me

    One more sol'n is to bind the Add Existing button of the subgird(using http://www.mscrmking.com/2011/06/crm-2011-how-to-filter-add-existing)

    but that too didn’t work for me...

    Please it will be real help if u can give me some sol'n so that I can show user the records related to the selected values from lookup...

    any sort of suggestions are  welcomed...

    Thanks

    Sneha



    Thanks! Sneha

    Friday, February 17, 2012 9:05 AM
  • Dear Sneha,

       Since you are usiing Fetch Xml it will be listing all the records based on the condition you have specified in the FetchXml and if you want the record to be not listed in your Sub Grid means the record should not match your condition in the FetchXML for that you have create a sperate logic for making the record to not to match your FetchXml Condition and you can achieve this through adding Custom buttons (i guess) or you can write your logic to make this ...


    With Regards Athul MT If you find this answer as help ful please vote as helpful and if you find this answer Please Mark It as Answer :)

    Friday, February 17, 2012 11:38 AM
  • Hi Athul,

    The records which are listed as per fecthxml are firstly listed in subgrid as per the valued seleted in lookup now  user can see the list of related record and as per he can delete some of them(records) for that subgrid,so I was in search of remove button....


    Thanks! Sneha

    Friday, February 17, 2012 11:44 AM
  • Hi Sneha,

    I think the issue here is that there is no “direct” relationship between the Account and the records you are wanting to show within the sub-grid.
    I believe that the buttons on the ribbon will apply to sub-grids only where there is a “direct” relationship between the records.

    For example, on the Account form, you have a “Primary Contact” lookup (relationship to a Contact), and are showing a sub-grid of “Books” (custom entity, related to the selected Contact).
    The link between the Account form and the “Book” sub-grid is simply that you are showing “All Records” (ie. there is actually no relationship between the Account and Books) – all you are doing is filtering this list of “Books” to only show those related to the selected “Contact”, this still does not change the relationship between the sub-grid and the parent form.

    As such, because there is no relationship, the options you will have on the ribbon when the sub-grid is selected will be the same as those available when looking at any Book view (for example) outside the scope of a related record – there is no recognition of a relationship because it doesn’t exist.

    I think to achieve what you are asking for, you need to do the following:

    • Create a relationship (many to many) between Accounts and Books – and do not show this in the left navigation menus.  
    • When a Contact is associated to a Book, also associate the Book to the Account (related to the Contact) … and visa versa, plugin will be best for this.
    • *When a Contact is disassociated from a Book, also disassociate the Book from the Account (related to the Contact) IF there are no other child Contacts also linked to this Book… and visa versa, plugin will be best for this.


    This is assuming:

    • Each Account is related to many Contacts; Each Contact is related to one Account
    • Each Contact is related to many Books; Each Book can be related to many Contacts
    • Each Book can be related to many Accounts; Each Account can be related to many Books

    (Not sure if the above in what you have/are after … just taking a guess!)

    This should now allow you to add a sub-grid on the Account form selecting “Only Related Records” and then the new relationship to Books – as this will be a direct relationship, you should now be able to see the “Remove” button.

    In order to keep all the relationships in-sync, you will also need to do the following:

    • When a Book is dissociated from an Account (using the “remove” button for the sub-grid), disassociated the Book from the selected “Primary Contact” (on the Account) … this should in turn trigger a check on (*) to  verify if the relationship between the Book and the Account also needs to be removed.

    I haven’t actually tested this (sorry I’m not very technical) but this should be one way of giving you the desired effect …

    Also, this is quite a bit of work so I would re-confirm the requirement for this to ensure it is essential ... otherwise, it may just be easier to tell users to open the related “Contact” and view/add/remove the Books (for example) directly from there … !!

    Good luck!

    Thanks,
    Maryse


    The xRM Architect:

    Tuesday, February 21, 2012 12:06 AM
  • Hi Maryse,

    thank you so much ur reply and time ,

    I have go through ur reply, u have correctly understood my requirement,

    When an record is selected in Primary Contact lookup all the record are listed in subgrid of Books which have same contact 

    now user can delete some of the books from subgrid.

    I will work on ur suggestion as I want it achieve it any how.

    can u suggest me how to write plugin for associate and dissociated relation

    I am truly thankful to you.



    Thanks! Sneha

    Tuesday, February 21, 2012 7:03 AM
  • Hi Sneha,

    No worries, glad I was able to help :)

    I haven’t written any plugins before but these seem to be the right events to use …

    AssociateRequest Class
    http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.associaterequest.aspx

    DisassociateRequest Class
    http://technet.microsoft.com/en-us/library/microsoft.xrm.sdk.messages.disassociaterequest.aspx

    You can also get more details in the CRM 2011 SDK:
    http://www.microsoft.com/download/en/details.aspx?id=24004&lc=1033

    Good luck!

    Thanks,
    Maryse

    The xRM Architect:

    Tuesday, February 21, 2012 10:45 PM