Showing results for 
Search instead for 
Do you mean 
Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Copper Super Contributor
Posts: 21
Registered: ‎12-08-2009

How to relate a CONTACT to multiple ACCOUNTS in a different way?

I am trying to create a brand new smart part which would create a brand new loose association between a CONTACT and many ACCOUNTS.  Each of our contacts gets a special report for MANY accounts, not just the single account that the contact is already tied to. I need a new tab on the CONTACT screen, that contains a data grid, which will list accounts and allow add/remove of ACCOUNTS via a lookup.  

 

I’ve created a new table called ReportLink. It extends the CONTACT entity, and also contains a ACCOUNTID field which I added via db manager. I’ve already create a new form (smart part tab), with a grid and datasource.  

 

I’m specifically struggling when trying to set the properties correctly (on the ds and grid) so that the grid only shows Accounts associated to the Contact found in the new ReportLink table. Can you give me your thoughts on how’d you do this?

Employee
Posts: 535
Registered: ‎03-30-2009

Re: How to relate a CONTACT to multiple ACCOUNTS in a different way?

Turns out I've done pretty much that same thing recently. 

 

This is a quick review all from memory, hopefully I've not forgotten something critical.

 

For my scenario, the extra contacts where thought of as being children of an Account - we called them AssociatedContacts (that was table name as well I believe).

 

Table/Entity looked something like this:

AssociatedContact

AssociatedContactId

AccountId

ContactId

Role  (picklist)

 

 

I created a Parent-Child relationship between Account and AssocatedContact (1:M with Save/Update/Delete for cascade).

I also created another Parent-Child relationship between Contact and  AssociatedContact (1:M with Save/Update/Delete for cascade).

 

On the Account Mainview, I created a tab form (Quickform smartpart). I used the QuickForm wizard to create an Account data bound grid using the Account.AssocaitedContacts relationship.

 

On the Contact Mainview,  I created a tab form (Quickform smartpart). I used the QuickForm wizard to create a Contact data bound grid using the Account.AssocaitedContacts relationship.

 

Using the AssocaitedContact entity, create a data bound Insert form - the naming convention I used is AddEditAssocaitedContact. On this form, have a LookupControl for Account and another Lookup Control for Contact, plus any other control needed for properties you may have created for the AssocaitedContact entity.

Add this QuickForm to both the Account Detail and Contact Detail MainView pages (as a SmartPart configured for Dialog mode).

 

On both of the tab forms that have the grids, add an "Edit" column (and a "Delete" column if desired).  For the Edit column - configure to use your AddEditAssocaitedContact QuickForm (I like to override the Title and set it to "Edit Associated Contact" 

 

On both of the tab forms that have the grids, create a toolbar item (button)using the "+" icon for adding records. For the button, choose the "Insert Child Dialog" Action and select your AddEditAssociatedContact QuickForm. Note - I like to override the Title and use "Add Associated Contact"

 

Note: on the AddEditAssociatedContact form, I may have had to write some Form OnLoad logic for detecting that the form is in Add mode (vs. Edit existing record mode), and if in Add mode - I probably had to figure out if I was being launched from Account MainView or ContactMainview so I could initialize the correct lookup (the Account lookup vs. the Contact Lookup).  I think I used Sage.Application.ApplicationContext to make that determination.

 

I was pleasantly surprised how well this worked out as I expected a bit of struggle with the dual parentage relationships.  Configured in this manner, the AssociatedContacts records are automatically deleted if either the Account or the Contact is deleted form the DB.

 

Hope that helps... If you get hung up let me know and I'll see if I can dig out a bit of code from that project.

 

 

Todd Hardin
SalesLogix Professional Services Group
Copper Super Contributor
Posts: 21
Registered: ‎12-08-2009

Re: How to relate a CONTACT to multiple ACCOUNTS in a different way?

Thank you. Wow. That's a lot.

 

I now have a new ReportLink entity. This is a lot like your AssociatedContact. I've linked it to an Account and a Contact; I have created the relationships. I've created a new form called ReportLinkForm, and have added a datasource and a datagrid. I'm really not sure what properties to set on the datasource and grid. Your thoughts?

 

Why must I create a brand new form to allow new associations. Can't I use the built-in lookups screen to lookup and select new Accounts, to associate to my contact?

Highlighted
Employee
Posts: 535
Registered: ‎03-30-2009

Re: How to relate a CONTACT to multiple ACCOUNTS in a different way?

Assuming the ReportLink form is bound to the Account entity, the datasource for the grid would work via a GetBy relationship  - so use the Account entity and the relationship is the one you defined between the Account and ReportLink entities. (probably Account.ReportLinks)

 

 

I created an AddEditForm (databound to your ReportLink entity) because I had 2 more entity properties that I needed to allow the user to edit. 

 

I'm not 100% certain you can use the built-in toolbar "Lookup" actions - have not tried it, sounds good in theory though.

 

 

Todd Hardin
SalesLogix Professional Services Group