locked
Plugin when adding associated record (N-N) RRS feed

  • Question

  •  

    Hi,

     

    I have following situation. I have a N to N relationship between Salesorder and Systemuser. On an order i can add Account Managers (=systemusers).

    When i add a systemuser as an account manager to an order, i want to share that order with the user i added. I already tried a post-update order plugin, but that doesnt fire when you add an associated record. What plugin message do i need to use?

     

    I know there are lots of messages that aren't enabled by default in the sdkmessagebase table. Do i have to enable one in there? wich?

     

    Regards,

     

    CypressPhill

    Saturday, March 8, 2008 12:50 PM

Answers

  • Hi again,

     

    I found the solution after a colleague and i browsed the SdkMessage* tables in the CRM database. This may be unsupported but it does the trick.

    The messages i was looking for is called 'AssociateEntities' and is by default 'IsCustomProcessingStepAllowed = false'

    You can find the id for the message in 'SdkMessageBase'. With that id you can set 'IsCustomProcessingStepAllowed' to true.

    Next you have to make the following changes to the Plugin registration tool:

    • add these two lines to the GetMessageNames() method:
      • al.Add("AssociateEntities");

      • al.Add("DisassociateEntities");

    • add these two lines to the GetMessagePropertyNames() method:

      • h.Add("AssociateEntities","MonikerToBusinessEntityMoniker(Moniker1)");

      • h.Add("DisassociateEntities", "MonikerToBusinessEntityMoniker(Moniker1)");

    When you register the plugin you have following restrictions:

    • You cannot select an entity type. you have to select 'None'
    • You cannot select any type of Pre or Post images (if you have already extended your PluginRegistration project with this)

    Since this plugin will be called every time you add a record to a many-to-many relationship, you have to make sure to thoroughly check the input parameters Moniker1.Name, Moniker2.Name and RelationshipName. RelationshipName contains the schema name of your relationship.

     

    With this information you can enable all the other messages that are not available by default.

     

    Good luck,

     

    Philippe

    Monday, March 10, 2008 2:51 PM

All replies

  • Dear,

     

    Yes you can achieve this through many to many relationships in Plugins

     

    http://blogs.msdn.com/crm/archive/2008/03/07/developing-plug-ins-for-crm-4-0.aspx

     

    use this IPluginExecutionContext

     

    Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Sunday, March 9, 2008 11:04 AM
    Moderator
  • Hi CypressPhill,

    unfortunately, messages for associated entities, i.e. AssociateEntities and DisassociateEntities are not available in plugins.

    To achieve what you want I suggest that, instead of a built-in N:N relationship,
    you introduce explicit intermediate salesorder_systemuser entity and build N:1:N relationship. The downside is that data entering process for the user becomes a little more complicated, the upside (apart from a working plugin) is ability to add additional attributes to the relationship.

    Hope this helps
    George
    Sunday, March 9, 2008 4:30 PM
    Moderator
  • Hi,

     

    thank you for the quick responses.

     

    I honestly can't believe that there is no plugin message to handle adding records in a many to many relationship. I really don't understand microsoft on this. They finally introduce many to many relationships and then they don't make messages to manipulate them? so they force you to make a many to 1 to many relationship all over again. What is the logic behind that?

     

    Regards,

    Philippe

    Monday, March 10, 2008 9:35 AM
  • Hi again,

     

    I found the solution after a colleague and i browsed the SdkMessage* tables in the CRM database. This may be unsupported but it does the trick.

    The messages i was looking for is called 'AssociateEntities' and is by default 'IsCustomProcessingStepAllowed = false'

    You can find the id for the message in 'SdkMessageBase'. With that id you can set 'IsCustomProcessingStepAllowed' to true.

    Next you have to make the following changes to the Plugin registration tool:

    • add these two lines to the GetMessageNames() method:
      • al.Add("AssociateEntities");

      • al.Add("DisassociateEntities");

    • add these two lines to the GetMessagePropertyNames() method:

      • h.Add("AssociateEntities","MonikerToBusinessEntityMoniker(Moniker1)");

      • h.Add("DisassociateEntities", "MonikerToBusinessEntityMoniker(Moniker1)");

    When you register the plugin you have following restrictions:

    • You cannot select an entity type. you have to select 'None'
    • You cannot select any type of Pre or Post images (if you have already extended your PluginRegistration project with this)

    Since this plugin will be called every time you add a record to a many-to-many relationship, you have to make sure to thoroughly check the input parameters Moniker1.Name, Moniker2.Name and RelationshipName. RelationshipName contains the schema name of your relationship.

     

    With this information you can enable all the other messages that are not available by default.

     

    Good luck,

     

    Philippe

    Monday, March 10, 2008 2:51 PM
  • Hello. You're saying it may be unsupported, but I need this sort of message for one of my customizations. Can you tell me if you had any problems after implementing it?

    Thanks,
    Florin
    Tuesday, April 7, 2009 1:13 PM
  • Hi George,

    Can u please explain how we can create n:1:n relationship...i,m confused on that.It wud be gud if u give some example and explain.thanks in advance

    Wednesday, April 13, 2011 10:55 AM