Ability to retrieve related records
ptdesign opened this issue · 4 comments
ptdesign commented
Ability to retrieve related records
salaros commented
Could you please provide an example in words or pseudo-code of such functionality?
ptdesign commented
Sure,
Example, find Services or Tickets that are related to a contact
$client->entities->findMany('Services', "from Module Contacts"
salaros commented
Hi again,
I read vTiger API documentation and there is no need to update my library, because CRM already provides such functionality. Actually it even gives you a choice between pulling out all the related records or by applying some search filter:
$johnSmithId = $client->entities->getID('Contacts', [
'firstname' => 'John',
'lastname' => 'Smith',
]);
// List ALL the tickets created for John Smith
$entities=$client->invokeOperation('retrieve_related', [
'id' => $johnSmithId,
'relatedType' => 'HelpDesk',
'relatedLabel' => 'HelpDesk'
], 'GET');
// ..alternatively you could use SQL-like queries with WHERE, ORDER BY, LIMIT etc
$entities=$client->invokeOperation('query_related', [
'query' => "SELECT * FROM HelpDesk WHERE ticket_title LIKE '%problem%' ORDERBY modifiedtime LIMIT 10",
'id' => $johnSmithId,
'relatedLabel' => 'HelpDesk'
], 'GET');
array(1) {
[0]=>
array(23) {
["ticket_no"]=>
string(3) "TT1"
["ticketpriorities"]=>
string(3) "Low"
["ticketstatus"]=>
string(11) "In Progress"
["ticket_title"]=>
string(17) "Problem with APIs"
["contact_id"]=>
string(4) "12x8"
...
}
}
Please note that invokeOperation
method can be used to invoke ANY operation defined in vtiger_ws_operation
table.
You can find more info on defining you own Web Services operations here.