locked
Best way to retrieve data after adding an N-N relationship RRS feed

  • Question

  • Hello,

    Environment = CRM 2013 SP1.

    I have a custom entity call "SITE". I create 2 N-N relationship: one with contact-site  and one with account-site.
    As you know, contact is link to account.
    When i'm adding a contact to my custom entity "Site" using add button in top of the grid n-n, I would like to automatically add the account of this contact to the second relationship site-account.
    When i'm deleting a contact linked to "Site" in grid n-n, i would like to automatically remove the  linked account of this contact to the second relationship site-account.
    I know this may sound strange.

    I don't think there is an event on the onadd of the grid contact-site.
    Is it maybe possible with a custom workflow assembly ? How ?

    Thank you in advance.
    K


    • Edited by K. MA Thursday, January 8, 2015 9:22 PM
    Thursday, January 8, 2015 9:21 PM

Answers

  • The message should be either 'Associate' or 'Disassociate'.

    Primary entity should be your SITE custom entity.

    No secondary entity is needed, I'd leave it blank.

    The rest of the settings in your screenshot look fine - post-operation, as you want the plugin to fire after the association/disassociation occurs.

    In your code, the entity retrieved will be the SITE entity record - you will have do a lookup on the associated Account (via the Contact record being associated to the SITE entity record).

    Good luck!

    • Marked as answer by K. MA Friday, January 9, 2015 3:27 PM
    Friday, January 9, 2015 3:26 PM

All replies

  • Hi K,

       I would write a plugin that fires on the Associate/Disassociate of a SITE entity record. The plugin code would verify the association is with a Contact record, and if so, would then look up the account from the contact and associate that account to the SITE record. Conversely, when a Contact entity record is being disassociated, the plugin code would verify the disassociation is from a Contact record, and if so, would again look up the account from the contact and disassociate that account from the SITE record. Note that it is important that the code checks that the association/disassociation is coming from a Contact record (and not an Account record), since the code would associate an Account record to the SITE record, which will fire the plugin again, and you don't want an endless loop.

    Hope that helps,

    John

    • Proposed as answer by Kalim Khan Friday, January 9, 2015 7:16 AM
    Friday, January 9, 2015 2:47 AM
  • Hello Kalim,

    Thank you for your answer.

    Can you help me to configure the registration tool ?
    Message = Associate ?
    Primary entity = ?
    Secondary entity = ?
    In my method execute, the entity retrivied in the InputParameter will be Chantier, Contact or ... ? 

    Thank you in advance


    • Edited by K. MA Friday, January 9, 2015 2:52 PM
    Friday, January 9, 2015 2:27 PM
  • The message should be either 'Associate' or 'Disassociate'.

    Primary entity should be your SITE custom entity.

    No secondary entity is needed, I'd leave it blank.

    The rest of the settings in your screenshot look fine - post-operation, as you want the plugin to fire after the association/disassociation occurs.

    In your code, the entity retrieved will be the SITE entity record - you will have do a lookup on the associated Account (via the Contact record being associated to the SITE entity record).

    Good luck!

    • Marked as answer by K. MA Friday, January 9, 2015 3:27 PM
    Friday, January 9, 2015 3:26 PM