locked
One to One Relationship RRS feed

  • Question

  • Hi there,

     

    In CRM 4.0, is there any way to implement the One to One relationship between two entities ?

     

    Thanks !

    Wednesday, December 10, 2008 4:27 PM

Answers

  • Hi

     

    I’ve checked to see if this (using js to make this work) is feasible and came to a conclusion that its not.

    Here are the reasons why this is not an acceptable solution:

    To make this simple I’ll use the terms One and Many as entity types.

     

    Consider the following scenario:

    You have a single One entity instance called A1 and a series of Many instances called B1,B2,B3

     

    When you associate B1 record to A1 from A1 grid you cannot remove the link to B1 record unless you open the B1 record, remove the lookup reference to A1 and save the record. Using the Delete button will delete B1 from the system.

     

    You need to make the same checks from the B1 crmForm side since nothing is stopping the user from attaching the B2, B3 records to A1 although it might already have a relationship with B1 record.

     

    You still need to write Unsopported javascript which renders this whole idea as unacceptable.

    The solution I mentioned above is the best/supported solution.

     

    Adi

    Friday, December 12, 2008 10:01 PM

All replies

  • Hi,

     

    CRM 4.0 does not support 1:1 or Any:Any relationships, unless you do some stuff to pretend your 1:N relationship is a 1:1 one... If you really need a one-to-one relationship, you could create one-to-many and then use JScript to hide it from the primary entity or use the plugin code to prevent the users from adding a new record on the "many" side if one already exists. However, this would probably not solve your issue...

     

    Kind regards,

    Kuba Skalbania

     

    Wednesday, December 10, 2008 4:59 PM
  • Does anyone know any good article or blog entry related to that which can be a good starting point?

     

    Thanks!

    Wednesday, December 10, 2008 10:08 PM
  • Following from CRM SDK could be a good starting point for you;

     

    http://msdn.microsoft.com/en-us/library/cc296262.aspx

     

    Friday, December 12, 2008 1:51 AM
    Moderator
  • From the UI Perspective creating a 1 to 1 relationship is easy. You simply add a 1 to many relationships from each side and choose not to show the navigation menu (many grid) of the other side when you create the relationship.

    Then simply add each side lookup to the crmform so eventually you’ll have a left side with a right_id lookup and a right side with a left_id lookup.

     

    The problematic part is maintaining the data integrity. The following scenario illustrates the complexity which all other scenarios derive form and the actions needed to be taken. For simplicity I’ll use left and right as entities.

     

    Consider the following:

    A anc C are instances of Left entity type and B and D are instances of Right entity type.

     

    Lets say you have a record Left A that points to Right B (A <--> B) and Right B that points back to Left A.

    No you have another record where Left C points to Right D and vise versa (C <--> D).

     

    Scenario:

    Associate Left A to Right D

     

    Trigger:

    Left A Form Triggers the lookup change from B to D:

     

    Plug-in Code:

    1.

    Event:  Left Post Update.

    Target: Nullify Right B Left_id lookup (Since it’s not pointing to A anymore)

    Action: Since B was referenced by A before the change you can take the Right B key from A right_id PreImage lookup and update it with null values.

    Triggers: Right Post Update. So If Right B left_id lookup is null then exit.

     

    2

    Event:  Left Post Update or Left Post Create

    Target: Update Right D so it would point to Left A.

    Action: Take D key from the A Target Entity right_id lookup and update D left_id with A key.

    Triggers: Right post update à 3

     

    3

    Event:  Right Post Update

    Target: Nullify Left C right_id lookup (Since D is not pointing to it anymore) 

    Action: Right D referenced Left C,Left C key (or D left_id lookup) can be taken from the PreImage like (1) above.

    Triggers: Left post update so if the C right_id lookup is null then exit.

     

    If you write this correctly the same plug-in code can serve both sides (left and right).

    And you might need to manage the calls depth as well.

     

    Hope this makes sense

    And good luck.

     

    Adi

     

                 

     

     

    Friday, December 12, 2008 4:09 AM
  • Hi there,

     

    Thanks for the support !

     

    Is it possible to use the Javascript in this case. Please let me know if this is possible.

     

    When user opens the entity to edit. In left hand navigation it shows the link for the relationships.

     

    User clicks on that relationship link.

     

    Javascript checks If there is already any record in the grid then it will make the "New" button invisible.

    Otherwise "New" button will be visible.

     

    Thanks!

    Friday, December 12, 2008 4:57 PM
  • Hi

     

    I’ve checked to see if this (using js to make this work) is feasible and came to a conclusion that its not.

    Here are the reasons why this is not an acceptable solution:

    To make this simple I’ll use the terms One and Many as entity types.

     

    Consider the following scenario:

    You have a single One entity instance called A1 and a series of Many instances called B1,B2,B3

     

    When you associate B1 record to A1 from A1 grid you cannot remove the link to B1 record unless you open the B1 record, remove the lookup reference to A1 and save the record. Using the Delete button will delete B1 from the system.

     

    You need to make the same checks from the B1 crmForm side since nothing is stopping the user from attaching the B2, B3 records to A1 although it might already have a relationship with B1 record.

     

    You still need to write Unsopported javascript which renders this whole idea as unacceptable.

    The solution I mentioned above is the best/supported solution.

     

    Adi

    Friday, December 12, 2008 10:01 PM
  • Dear Adi,

     

    Can you pls follow the link and address the issue. Would appreciate!!

     

    http://forums.microsoft.com/dynamics/ShowPost.aspx?postid=4265073&isthread=false&siteid=27&authhash=c7371d6fcf6d1e02a608e373e32533362d39428e&ticks=633659369243096061

     

    Thanx in advance.

     

    Best

    Prince

    Saturday, December 27, 2008 9:23 AM