usage of link_name_to_fields_array with get_entry_list
hi,
i'm struggeling trying to use link_name_to_fields_array with get_entry_list. i've taked a closer look at the wiki, but didn't found anything related on how to use it.
any chances, you would help me figuering out how to use it ?
regards,
I'm happy to look into it when I have a free moment - it looks like that facilitates retrieving related beans from other modules at the same time that you retrieve the initial record, but it isn't implemented in the webservices library at present. Do you have an example of the modules you're working with / trying to retrieve from? On the main rest.php page the example they use is for retrieving the Email Addresses for a Contact. As you can't do the same using a single call (yet), the approach for getting them on a per-contact basis would look like this:
# `c` is a Contact Entry
emails = c.get_related('EmailAddresses', fields = ['id',
'email_address', 'opt_out', 'primary_address'], relateby = 'email_addresses')
When retrieving related entries, the relateby keyword argument should be the name of the relationship (something from c._module._relationships.keys()).
Let me know if that helps, or if you have other questions. --Daniel
On Tue, May 12, 2015 at 9:45 AM, xinity [email protected] wrote:
hi,
i'm struggeling trying to use link_name_to_fields_array with get_entry_list. i've taked a closer look at the wiki, but didn't found anything related on how to use it.
any chances, you would help me figuering out how to use it ?
regards,
— Reply to this email directly or view it on GitHub https://github.com/gddc/python_webservices_library/issues/29.
i've taken a look at sugarentry.py (i've changed it a little to handle queries limit :)): res = self._module._connection.get_entry_list(self._module._name,qstring, '', 0,list(fieldlist), list(fieldlist),0,0,0)
but what would be link_name_to_fields_array is the "second": list(fieldlist)
but the sugarcrm documentation says: A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
so what i was trying to do is "translating": array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))) in python, but i've failed :(
on my case, i'm trying to pull account name using a relation betweeen our own custom sugarCRM module and the account module.
i've also looked at sugarcrm 0.1 module : https://pypi.python.org/pypi/sugarcrm/0.1 wich describe get_entry_list like this:
get_entry_list(query_object, fields=[], links={}, order_by=”“, max_results=0, offset=0, deleted=False, favorites=False) Retrieves a list of objects based on query specifications.
Get a list of all Notes with a name that begins with "Test"
note_query = sugarcrm.Note(name="Test%") notes = session.get_entry_list(note_query) for note in notes: print note.name
Get a list of all Opportunities created since Sept 1, 2014 and include
data about link contacts with each Opportunitity returned
q = sugarcrm.Opportunity() q.query = "opportunities.date_entered > '2014-09-01'" links = {'Contacts': ['id', 'first_name', 'last_name']} results = session.get_entry_list(q, links=links) for o in results: for c in o.contacts: print o.id, c.id, c.first_name, c.last_name
so i'm confused about how to implement this.
if you have any tips ... :)
I've updated the library to include support for that argument to get_entry_list. Sample usage would look something like this:
# `S` is a connection to my Sugar Instance
C = S['Contacts']
q = C.query(links_to_names = [{'name': 'email_addresses', 'value':
['id', 'email_address']}]) q = q.filter(last_name__eq = 'Casper') cs = list(q)
When the entries are retrieved you'll end up with a member attribute on
each SugarEntry for related_beans which will contain the extra
information retrieved from the related modules.
Let me know if that helps, or if you have other questions.
On Wed, May 13, 2015 at 12:12 AM, xinity [email protected] wrote:
i've taken a look at sugarentry.py (i've changed it a little to handle queries limit :)): res = self._module._connection.get_entry_list(self._module._name,qstring, '', 0,list(fieldlist), list(fieldlist),0,0,0)
but what would be link_name_to_fields_array is the "second": list(fieldlist)
but the sugarcrm documentation says: A list of link_names and for each link_name, what fields value to be returned. For ex.'link_name_to_fields_array' => array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address')))
so what i was trying to do is "translating": array(array('name' => 'email_addresses', 'value' => array('id', 'email_address', 'opt_out', 'primary_address'))) in python, but i've failed :(
on my case, i'm trying to pull account name using a relation betweeen our own custom sugarCRM module and the account module.
i've also looked at sugarcrm 0.1 module : https://pypi.python.org/pypi/sugarcrm/0.1 wich describe get_entry_list like this:
get_entry_list(query_object, fields=[], links={}, order_by=”“, max_results=0, offset=0, deleted=False, favorites=False) Retrieves a list of objects based on query specifications. Get a list of all Notes with a name that begins with "Test"
note_query = sugarcrm.Note(name="Test%") notes = session.get_entry_list(note_query) for note in notes: print note.name Get a list of all Opportunities created since Sept 1, 2014 and include data about link contacts with each Opportunitity returned
q = sugarcrm.Opportunity() q.query = "opportunities.date_entered > '2014-09-01'" links = {'Contacts': ['id', 'first_name', 'last_name']} results = session.get_entry_list(q, links=links) for o in results: for c in o.contacts: print o.id, c.id, c.first_name, c.last_name
so i'm confused about how to implement this.
if you have any tips ... :)
— Reply to this email directly or view it on GitHub https://github.com/gddc/python_webservices_library/issues/29#issuecomment-101526228 .
simply awesome !!
i'll test it by tomorrow and let you know
thanks a lot for your blaizing fast help :)
It should work passably - it's worth mentioning that it doesn't actually create SugarEntry instances for the related beans, in large part because there's not presently a look up from those relationships to their proper Module name. I'll look into that.
I also just pushed a change that adds that same support to the get_related method on an Entry, so I was able to do this:
cs = b.get_related("Contacts", links_to_fields = [{'name': 'email_addresses', 'value': ['id', 'email_address', 'opt_out']}])
where b was an instance of an Account and the returned Contacts all had
related_beans that contained all of their email addresses.
--Dan
On Thu, May 14, 2015 at 12:39 PM, xinity [email protected] wrote:
simply awesome !!
i'll test it by tomorrow and let you know
thanks a lot for your blaizing fast help :)
— Reply to this email directly or view it on GitHub https://github.com/gddc/python_webservices_library/issues/29#issuecomment-102131534 .
i think you "should" change this: resp_data = self._connection.get_entry_list(self._name, query_str, '', start + offset, fields, links_to_names, total - len(entry_list), 0)
to this: resp_data = self._connection.get_entry_list(self._name, query_str, '', start + offset, fields, links_to_names, total - len(entry_list), 0,0,0)
or else you would miss supporting: max_results Integer The maximum number of results to return. deleted Integer If deleted records should be included in the results. favorites Boolean If only records marked as favorites should be returned.
this has helped me little to handle max items returned by the query.
i'll test today link_to_names and let you know how it goes
thanks again for your precious help,
I'll take a look ... You're probably right about the max results and favorites fields. The library has kind of been implemented on an as-needed basis and I haven't run into those yet. On May 15, 2015 12:35 AM, "xinity" [email protected] wrote:
i think you "should" change this: resp_data = self._connection.get_entry_list(self._name, query_str, '', start + offset, fields, links_to_names, total - len(entry_list), 0)
to this: resp_data = self._connection.get_entry_list(self._name, query_str, '', start + offset, fields, links_to_names, total - len(entry_list), 0,0,0)
or else you would miss supporting: max_results Integer The maximum number of results to return. deleted Integer If deleted records should be included in the results. favorites Boolean If only records marked as favorites should be returned.
this has helped me little to handle max items returned by the query.
i'll test today link_to_names and let you know how it goes
thanks again for your precious help,
— Reply to this email directly or view it on GitHub https://github.com/gddc/python_webservices_library/issues/29#issuecomment-102283344 .
let me know, if you want more feedback :)
by the way, link_fields_names works like a charm, as i forgot it's a one to many relation i had to rethink my python module :)
Things are going great so far, not tested the get-related, but get-entry-list works great now