Forums

Forums / Developing Portals / Add/remove N:N relationship

Add/remove N:N relationship

Thread is closed for posting
8 posts, 2 answered
  1. julien.biedermann
    julien.biedermann avatar
    17 posts
    Registered:
    16 Jun 2016
    06 Jul 2016
    Link to this post
    Hello,

    I want that my connected user (contact) can add/remove skills on his profile page.

    To do that, I used a sub-grid with the "add existing records" feature. It is working to add skills but there is no way to remove a skill.

    What do you propose to achieve that ?

    Thank you,
    Julien
  2. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    07 Jul 2016 in reply to julien.biedermann
    Link to this post
    Hello Julien,

    Does enabling deleting of records on the Sub Grid not work in this case?

    Deleting items from the list should unrelate them, and this would be the same as "Removing a skill"

    Regards,
    Clinton
  3. julien.biedermann
    julien.biedermann avatar
    17 posts
    Registered:
    16 Jun 2016
    07 Jul 2016 in reply to Clinton Bale
    Link to this post
    Hello Clinton,

    Thanks for your answer. When enabling delete of records on the sub-grid, the record (skill) is deleted not unrelated to the contact. After deleting a skill in the sub-grid, the record is deleted also in CRM.

    Best Regards,
    Julien
  4. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    07 Jul 2016 in reply to julien.biedermann
    Link to this post
    Julien,

    Is the sub-grid configured with a true N:N relationship?

    Currently the CRM Sub-Grid view will always "Delete" the primary entity of the fetch, regardless of what type of relationship it is.

    Can you provide an example of your fetch?

    Regards,
    Clinton

  5. julien.biedermann
    julien.biedermann avatar
    17 posts
    Registered:
    16 Jun 2016
    07 Jul 2016 in reply to Clinton Bale
    Link to this post
    Clinton,

    Yes the sub-grid is configured with a true N:N relationship.

    Here an fetch example :

    <?xml version="1.0"?>
    <fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">
    <entity name="gw_industry">
    <attribute name="gw_name"/>
    <attribute name="gw_industryid"/>
    <order descending="false" attribute="gw_name"/>
    <filter type="and">
    <condition attribute="statecode" value="0" operator="eq"/>
    </filter>
    <link-entity name="gw_contact_gw_industry" intersect="true" visible="false" to="gw_industryid" from="gw_industryid">
    <link-entity name="contact" to="contactid" from="contactid" alias="aa"> 
    <filter type="and">
    <condition attribute="contactid" value="@cid@" operator="eq"/>
    </filter>
    </link-entity>
    </link-entity>
    </entity>
    </fetch>

    Thanks,
    Julien
  6. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    07 Jul 2016 in reply to julien.biedermann
    Link to this post
    Hello Julien,

    Unfortunately dissociating records in N:N sub-grids is not supported out of the box. There are a few ways to do this however, but they may require some custom work.

    Have you considered using a fetch like this?

    <fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">
      <entity name="gw_contact_gw_industry">
        <link-entity name="contact" to="contactid" from="contactid" alias="aa">
          <filter type="and">
          <condition attribute="contactid" value="@cid@" operator="eq" />
          </filter>
        </link-entity>
        <link-entity name="gw_industry" from="gw_industryid" to="gw_industryid" alias="bb">
          <attribute name="gw_name" />
          <attribute name="gw_industryid" />
        </link-entity>
      </entity>
    </fetch>
    

    Otherwise you could create a custom grid column that calls a custom web service that will handle the disassociation for you.

    Regards,
    Clinton 
  7. phongchoi
    phongchoi avatar
    3 posts
    Registered:
    05 Jul 2016
    08 Jul 2016
    Link to this post
    Hello Clinton,

    ​Using the fetchxml as your suggested does not work.
    It throwns the following exception: "new_classid" is neither a DataColumn nor a DataRelation for table.

    Could you please explain more details about this option: "Otherwise you could create a custom grid column that calls a custom web service that will handle the disassociation for you." ?

    Many thanks,
    Phong
  8. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    13 Jul 2016 in reply to phongchoi
    Link to this post
    Phong,

    To fix the error, please try changing the selected relationship to one that has the PK of the primary entity in the FetchXml in the relationship.

    Also ensure AutomaticFetchFiltering is set to False

    Regards,
    Clinton
8 posts, 2 answered