AnsweredAssumed Answered

How to look up related data dynamically?

Question asked by Chad Hutchins on Jan 10, 2017
Latest reply on Jan 11, 2017 by Francesca Shiekh

Is there any generic code out there that can take something like "contacts.accounts.opportunities.sales_stage" given a contact record and retrieve the related data?

 

 

A couple examples:

 

1. Given "contacts.accounts.industry" and a contact record $contact, it would take the $contact record, find the parent account and return the industry field value on the parent account.

 

2. Or something more complex, take this string "contacts.accounts.opportunities.sales_stage" and a contact record $contact. It would grab the parent related account, grab the related opportunities on the account, then return an array of each opportunity's sales_stage value.

 

I've implemented this sort of thing many times for different reasons and I believe it is common developer use case, especially for integrations. It'd be awesome if we had a simple notation (ex. {module}.{related_module}.{field}) we could use to store the path we want then easily call for the value when we want it. 

 

I know you could create a calculated field for something like this, but that seems unnecessary behind the scenes if you're writing a customization. This gets even more difficult if you're trying to create a calculated field for an integration lots of Sugar customers will use for several reasons (customer on-boarding, module loader issues, on-demand restrictions, etc.) 

 

Does anything like this already exist in the Sugar codebase? Or are there any generic methods out there that handle something like this?

Outcomes